Browse Source

Parse correctly mappings where the binary has been deleted

Entry mappings of the form:
 "  02e00000-02e8a000: /foo/bin (deleted)"
are currently resulting in "(deleted)" being set as the build id.
Enforce the build id to be hex, and allow unrecognized junk to
be at the end of the mapping.
Raul Silvera 8 years ago
parent
commit
f99c95e2cb
2 changed files with 12 additions and 4 deletions
  1. 3
    3
      profile/legacy_profile.go
  2. 9
    1
      profile/legacy_profile_test.go

+ 3
- 3
profile/legacy_profile.go View File

57
 	cHex           = `(?:0x)?([[:xdigit:]]+)`
57
 	cHex           = `(?:0x)?([[:xdigit:]]+)`
58
 	cHexRange      = `\s*` + cHex + `[\s-]?` + oSpace + cHex + `:?`
58
 	cHexRange      = `\s*` + cHex + `[\s-]?` + oSpace + cHex + `:?`
59
 	cSpaceString   = `(?:\s+(\S+))?`
59
 	cSpaceString   = `(?:\s+(\S+))?`
60
-	cSpaceHex      = `\s+([[:xdigit:]]+)`
60
+	cSpaceHex      = `(?:\s+([[:xdigit:]]+))?`
61
 	cSpaceAtOffset = `(?:\s+\(@([[:xdigit:]]+)\))?`
61
 	cSpaceAtOffset = `(?:\s+\(@([[:xdigit:]]+)\))?`
62
 	cPerm          = `(?:\s+([-rwxp]+))?`
62
 	cPerm          = `(?:\s+([-rwxp]+))?`
63
 
63
 
64
-	procMapsRE  = regexp.MustCompile(`^` + cHexRange + cPerm + cSpaceHex + hexPair + spaceDigits + cSpaceString + `\s*$`)
65
-	briefMapsRE = regexp.MustCompile(`^` + cHexRange + cPerm + cSpaceString + cSpaceAtOffset + cSpaceString + `\s*$`)
64
+	procMapsRE  = regexp.MustCompile(`^` + cHexRange + cPerm + cSpaceHex + hexPair + spaceDigits + cSpaceString)
65
+	briefMapsRE = regexp.MustCompile(`^` + cHexRange + cPerm + cSpaceString + cSpaceAtOffset + cSpaceHex)
66
 )
66
 )
67
 
67
 
68
 func isSpaceOrComment(line string) bool {
68
 func isSpaceOrComment(line string) bool {

+ 9
- 1
profile/legacy_profile_test.go View File

157
 				File:   "/foo/bin",
157
 				File:   "/foo/bin",
158
 			},
158
 			},
159
 		},
159
 		},
160
+		{
161
+			entry: "  02e00000-02e8a000: /foo/bin (deleted)",
162
+			want: &Mapping{
163
+				Start: 0x2e00000,
164
+				Limit: 0x2e8a000,
165
+				File:  "/foo/bin",
166
+			},
167
+		},
160
 		{
168
 		{
161
 			entry: "  02e00000-02e8a000: /foo/bin",
169
 			entry: "  02e00000-02e8a000: /foo/bin",
162
 			want: &Mapping{
170
 			want: &Mapping{
218
 	} {
226
 	} {
219
 		got, err := parseMappingEntry(test.entry)
227
 		got, err := parseMappingEntry(test.entry)
220
 		if err != nil {
228
 		if err != nil {
221
-			t.Error(err)
229
+			t.Errorf("%s: %v", test.entry, err)
222
 		}
230
 		}
223
 		if !reflect.DeepEqual(test.want, got) {
231
 		if !reflect.DeepEqual(test.want, got) {
224
 			t.Errorf("%s want=%v got=%v", test.entry, test.want, got)
232
 			t.Errorf("%s want=%v got=%v", test.entry, test.want, got)