From be562dffcc62a7644ab55833c9650774fb462ebe Mon Sep 17 00:00:00 2001 From: Joey Jiao Date: Mon, 2 Sep 2024 12:57:44 +0800 Subject: pkg/report: support module format with stacktrace_build_id Call trace can have line like below printed by %pSb: func_name+0x254/0x5f0 [module_name b31b29679ab712c360bddd861f655ab24898b4db] --- pkg/report/linux.go | 9 ++++++++- pkg/report/linux_test.go | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'pkg/report') diff --git a/pkg/report/linux.go b/pkg/report/linux.go index 39825b2c9..1ac1b8ee9 100644 --- a/pkg/report/linux.go +++ b/pkg/report/linux.go @@ -455,6 +455,10 @@ func symbolizeLine(symbFunc func(bin string, pc uint64) ([]symbolizer.Frame, err if match[10] != -1 && match[11] != -1 { modName = string(line[match[10]:match[11]]) } + buildID := "" + if match[12] != -1 && match[13] != -1 { + buildID = string(line[match[12]:match[13]]) + } symb := ctx.symbols[modName][string(fn)] if len(symb) == 0 { return line @@ -487,6 +491,9 @@ func symbolizeLine(symbFunc func(bin string, pc uint64) ([]symbolizer.Frame, err path, _ := backend.CleanPath(frame.File, ctx.kernelObj, ctx.kernelSrc, ctx.kernelBuildSrc, nil) info := fmt.Sprintf(" %v:%v", path, frame.Line) modified := append([]byte{}, line...) + if buildID != "" { + modified = replace(modified, match[8], match[9], []byte(" ["+modName+"]")) + } modified = replace(modified, match[7], match[7], []byte(info)) if frame.Inline { end := match[7] + len(info) @@ -1063,7 +1070,7 @@ var linuxStallAnchorFrames = []*regexp.Regexp{ // nolint: lll var ( - linuxSymbolizeRe = regexp.MustCompile(`(?:\[\<(?:(?:0x)?[0-9a-f]+)\>\])?[ \t]+\(?(?:[0-9]+:)?([a-zA-Z0-9_.]+)\+0x([0-9a-f]+)/0x([0-9a-f]+)( ?\[([a-zA-Z0-9_.]+)\])?\)?`) + linuxSymbolizeRe = regexp.MustCompile(`(?:\[\<(?:(?:0x)?[0-9a-f]+)\>\])?[ \t]+\(?(?:[0-9]+:)?([a-zA-Z0-9_.]+)\+0x([0-9a-f]+)/0x([0-9a-f]+)( ?\[([a-zA-Z0-9_.]+)( .*)?\])?\)?`) linuxRipFrame = compile(`(?:IP|NIP|pc |PC is at):? (?:(?:[0-9]+:)?(?:{{PC}} +){0,2}{{FUNC}}|(?:[0-9]+:)?0x[0-9a-f]+|(?:[0-9]+:)?{{PC}} +\[< *\(null\)>\] +\(null\)|[0-9]+: +\(null\))`) linuxCallTrace = compile(`(?:Call (?:T|t)race:)|(?:Backtrace:)`) linuxCodeRe = regexp.MustCompile(`(?m)^\s*Code\:\s+((?:[A-Fa-f0-9\(\)\<\>]{2,8}\s*)*)\s*$`) diff --git a/pkg/report/linux_test.go b/pkg/report/linux_test.go index f24b72d59..bb19ed6bf 100644 --- a/pkg/report/linux_test.go +++ b/pkg/report/linux_test.go @@ -151,6 +151,12 @@ func TestLinuxSymbolizeLine(t *testing.T) { "[ 50.419727][ T3822] baz+0x101/0x200 [beep]\n", "[ 50.419727][ T3822] baz+0x101/0x200 baz.c:100 [beep]\n", }, + // Frame format with module+offset and stracktrace_build_id. + { + "[ 50.419727][ T3822] baz+0x101/0x200 [beep b31b29679ab712c360bddd861f655ab24898b4db]\n", + "[ 50.419727][ T3822] baz+0x101/0x200 baz.c:100 [beep]\n", + }, + // Frame format with module+offset for invalid module. { "[ 50.419727][ T3822] baz+0x101/0x200 [invalid_module]\n", -- cgit mrf-deployment