Ver código fonte

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 anos atrás
pai
commit
f99c95e2cb
2 arquivos alterados com 12 adições e 4 exclusões
  1. 3
    3
      profile/legacy_profile.go
  2. 9
    1
      profile/legacy_profile_test.go

+ 3
- 3
profile/legacy_profile.go Ver arquivo

@@ -57,12 +57,12 @@ var (
57 57
 	cHex           = `(?:0x)?([[:xdigit:]]+)`
58 58
 	cHexRange      = `\s*` + cHex + `[\s-]?` + oSpace + cHex + `:?`
59 59
 	cSpaceString   = `(?:\s+(\S+))?`
60
-	cSpaceHex      = `\s+([[:xdigit:]]+)`
60
+	cSpaceHex      = `(?:\s+([[:xdigit:]]+))?`
61 61
 	cSpaceAtOffset = `(?:\s+\(@([[:xdigit:]]+)\))?`
62 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 68
 func isSpaceOrComment(line string) bool {

+ 9
- 1
profile/legacy_profile_test.go Ver arquivo

@@ -157,6 +157,14 @@ func TestParseMappingEntry(t *testing.T) {
157 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 169
 			entry: "  02e00000-02e8a000: /foo/bin",
162 170
 			want: &Mapping{
@@ -218,7 +226,7 @@ func TestParseMappingEntry(t *testing.T) {
218 226
 	} {
219 227
 		got, err := parseMappingEntry(test.entry)
220 228
 		if err != nil {
221
-			t.Error(err)
229
+			t.Errorf("%s: %v", test.entry, err)
222 230
 		}
223 231
 		if !reflect.DeepEqual(test.want, got) {
224 232
 			t.Errorf("%s want=%v got=%v", test.entry, test.want, got)