Better error reporting if things go pear shaped.

This commit is contained in:
Ian A. Mason 2018-04-17 11:46:22 -07:00
parent 30cc3b22fa
commit 3ea1db0849
3 changed files with 41 additions and 11 deletions

View File

@ -4,7 +4,7 @@ To edit the code locally use the repository here:
Then do:
go install -a github.com/SRI-CSL/gllvm/cmd/...
go install github.com/SRI-CSL/gllvm/cmd/...
To format for the badge:

View File

@ -191,6 +191,9 @@ func parseSwitches() (ea extractionArgs) {
func handleExecutable(ea extractionArgs) {
artifactPaths := ea.Extractor(ea.InputFile)
LogInfo("handleExecutable: artifactPaths = %v\n", artifactPaths)
if len(artifactPaths) == 0 {
return
}
@ -211,6 +214,8 @@ func handleArchive(ea extractionArgs) {
var bcFiles []string
var artifactFiles []string
LogInfo("handleArchive: extractionArgs = %v\n", ea)
// Create tmp dir
tmpDirName, err := ioutil.TempDir("", "gllvm")
if err != nil {
@ -222,6 +227,9 @@ func handleArchive(ea extractionArgs) {
arArgs := ea.ArArgs
inputAbsPath, _ := filepath.Abs(ea.InputFile)
arArgs = append(arArgs, inputAbsPath)
LogInfo("handleArchive: executing ar %v %v\n", arArgs, tmpDirName)
success, err := execCmd("ar", arArgs, tmpDirName)
if !success {
LogFatal("Failed to extract object files from %s to %s because: %v.\n", ea.InputFile, tmpDirName, err)
@ -235,8 +243,10 @@ func handleArchive(ea extractionArgs) {
artifactPaths := ea.Extractor(path)
for _, artPath := range artifactPaths {
bcPath := resolveBitcodePath(artPath)
if bcPath != "" {
bcFiles = append(bcFiles, bcPath)
}
}
artifactFiles = append(artifactFiles, artifactPaths...)
}
}
@ -246,6 +256,9 @@ func handleArchive(ea extractionArgs) {
// Handle object files
filepath.Walk(tmpDirName, walkHandlingFunc)
LogDebug("handleArchive: walked %v\nartifactFiles:\n%v\nbcFiles:\n%v\n", tmpDirName, artifactFiles, bcFiles)
if len(bcFiles) > 0 {
// Build archive
if ea.BuildBitcodeArchive {
extractTimeLinkFiles(ea, bcFiles)
@ -257,6 +270,9 @@ func handleArchive(ea extractionArgs) {
if ea.WriteManifest {
writeManifest(ea, bcFiles, artifactFiles)
}
} else {
LogError("No bitcode files found\n")
}
}
func archiveBcFiles(ea extractionArgs, bcFiles []string) {
@ -349,6 +365,7 @@ func resolveBitcodePath(bcPath string) string {
}
return storeBcPath
}
LogWarning("Failed to find the file %v\n", bcPath)
return ""
}
return bcPath

View File

@ -54,6 +54,15 @@ var loggingLevels = map[string]int{
"DEBUG": debugV,
}
var loggingPrefixes = map[int]string{
errorV: "Error: ",
warningV: "Warning: ",
infoV: "Info: ",
debugV: "Debug: ",
}
//loggingLevel is the user configured level of logging: ERROR, WARNING, INFO, DEBUG
var loggingLevel = errorV
@ -86,6 +95,10 @@ func makeLogger(lvl int) func(format string, a ...interface{}) {
//and send output to both os.Stderr and loggingFilePointer. We wouldn't
//want the user to miss any excitement. Then the sanity checker would not
//need to futz with it.
prefix := loggingPrefixes[lvl]
if len(prefix) > 0 {
loggingFilePointer.WriteString(prefix)
}
loggingFilePointer.WriteString(msg)
}
}