Example #1
0
func TestSymbolizeStackwalk(t *testing.T) {
	files := []string{
		"stackwalk1.txt",
		"stackwalk2.txt",
	}

	for _, file := range files {
		filePath := testdata(file)
		expectedPath := filePath + ".expected"

		parser := NewStackwalkParser()
		inputData, err := testutils.ReadSourceFile(filePath)
		if err != nil {
			t.Errorf("%s: %v", filePath, err)
			continue
		}
		err = parser.ParseInput(string(inputData))
		if err != nil {
			t.Errorf("Error parsing input for %s: %v", file, err)
			continue
		}

		modules := parser.RequiredModules()
		tables := make([]breakpad.SymbolTable, len(modules))
		for i, module := range modules {
			name := module.ModuleName
			// Leave one module a mystery.
			if name == "libSystem.B.dylib" {
				name = "__not found__"
			}
			tables[i] = &testTable{
				name:   name,
				symbol: strings.Replace(module.ModuleName, " ", "_", -1),
			}
		}

		outputData, err := testutils.ReadSourceFile(expectedPath)
		if err != nil {
			t.Errorf("%s: %s", expectedPath, err)
		}

		actual := parser.Symbolize(tables)

		if err := testutils.CheckStringsEqual(string(outputData), actual); err != nil {
			t.Errorf("Input data for %s does not symbolize to expected output", file)
			t.Error(err)
		}
	}
}
Example #2
0
func TestSymbolize(t *testing.T) {
	const kBaseAddress = 0x666000
	table := &testSymbolTable{map[uint64]breakpad.Symbol{
		0x100:  breakpad.Symbol{Function: "MessageLoop::Run()", File: "message_loop.cc", Line: 40},
		0x150:  breakpad.Symbol{Function: "base::MessagePumpMac::DoDelayedWork()", File: "message_pump_mac.mm", Line: 88},
		0x990:  breakpad.Symbol{Function: "-[BrowserWindowController orderOut:]", File: "browser_window_controller.mm", Line: 222},
		0xFFF5: breakpad.Symbol{Function: "TSMGetCurrentDocument"},
		0xBBAD: breakpad.Symbol{Function: "+[_AClass someMethodSignature:]"},
	}}

	results := map[string]string{
		"0x666100 0x666990 0x675FF5": `0x00666100 [Fragment Test Module -	 message_loop.cc:40] MessageLoop::Run()
0x00666990 [Fragment Test Module -	 browser_window_controller.mm:222] -[BrowserWindowController orderOut:]
0x00675ff5 [Fragment Test Module +	 0xfff5] TSMGetCurrentDocument
`,
		"0x671BAD 0x666150 0x997AbC": `0x00671bad [Fragment Test Module +	 0xbbad] +[_AClass someMethodSignature:]
0x00666150 [Fragment Test Module -	 message_pump_mac.mm:88] base::MessagePumpMac::DoDelayedWork()
0x00997abc [Fragment Test Module +	 0x331abc] 
`,

		"NaN 0xABC123\t0x666990\n\r  LolCatsAreFunny\t\t\tHello \n\r\t\t\n\rKitty\n\n\n0x671BaD": `0x00000000 [ 	 ] NaN
0x00abc123 [Fragment Test Module +	 0x456123] 
0x00666990 [Fragment Test Module -	 browser_window_controller.mm:222] -[BrowserWindowController orderOut:]
0x00000000 [ 	 ] LolCatsAreFunny
0x00000000 [ 	 ] Hello
0x00000000 [ 	 ] Kitty
0x00671bad [Fragment Test Module +	 0xbbad] +[_AClass someMethodSignature:]
`,
	}

	for input, expected := range results {
		p := NewFragmentParser(kFragmentTestModule, "Foobad", kBaseAddress)
		err := p.ParseInput(input)
		if err != nil {
			t.Errorf("Error for input '%s': %v", input, err)
		}

		actual := p.Symbolize([]breakpad.SymbolTable{table})
		if err := testutils.CheckStringsEqual(expected, actual); err != nil {
			t.Errorf("Symbolization for input '%s' failed", input)
			t.Error(err)
		}
	}
}