Skip to content

Commit

Permalink
test for printing demangled names in disassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
kalyanac committed Mar 9, 2019
1 parent e71d09f commit da402b4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func symbolsFromBinaries(prof *profile.Profile, g *graph.Graph, rx *regexp.Regex
continue
}
for _, ms := range msyms {
// CKK fmt.Println(ms, " ", base, " ", f)
objSyms = append(objSyms,
&objSymbol{
sym: ms,
Expand Down Expand Up @@ -564,7 +565,9 @@ func nodesPerSymbol(ns graph.Nodes, symbols []*objSymbol) map[*objSymbol]graph.N
// Gather samples for this symbol.
for _, n := range ns {
address := n.Info.Address - s.base
// CKK fmt.Println(n.Info.Address, " ", s.base, " ",s.sym.Name, ": " ,address, " ", s.sym.Start, " ",s.sym.End)
if address >= s.sym.Start && address < s.sym.End {
// CKK fmt.Println(" adding: ",s)
symNodes[s] = append(symNodes[s], n)
}
}
Expand Down
66 changes: 66 additions & 0 deletions internal/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"regexp"
"runtime"
"strings"
"testing"

"github.com/google/pprof/internal/binutils"
Expand Down Expand Up @@ -100,6 +101,15 @@ var testM = []*profile.Mapping{
HasLineNumbers: true,
HasInlineFrames: true,
},
{
// Entry for disassembly demangle test
ID: 2,
File: "testdata/disasm.bin",
HasFunctions: true,
HasFilenames: true,
HasLineNumbers: true,
HasInlineFrames: true,
},
}

var testF = []*profile.Function{
Expand All @@ -123,6 +133,12 @@ var testF = []*profile.Function{
Name: "tee",
Filename: "/some/path/testdata/source2",
},
{
// Entry for disassembly demangle test
ID: 5,
Name: "_ZStL8__ioinit",
Filename: "testdata/disasm.bin",
},
}

var testL = []*profile.Location{
Expand Down Expand Up @@ -176,6 +192,17 @@ var testL = []*profile.Location{
},
},
},
{
ID: 6,
Mapping: testM[1],
Address: 2101617,
Line: []profile.Line{
{
Function: testF[4],
Line: 2,
},
},
},
}

var testProfile = &profile.Profile{
Expand Down Expand Up @@ -213,6 +240,45 @@ var testProfile = &profile.Profile{
Mapping: testM,
}

func TestPrintAssembly(t *testing.T) {
demangled := "ioinit"

sampleValue1 := func(v []int64) int64 {
return v[1]
}

asmProfile := testProfile.Copy()
asmProfile.Sample = []*profile.Sample{
{
Location: []*profile.Location{testL[5]},
Value: []int64{1, 1000},
},
}

tc := testcase{
rpt: New(
asmProfile,
&Options{
OutputFormat: Dis,
Symbol: regexp.MustCompile(`.`),
TrimPath: "/some/path",
SampleValue: sampleValue1,
},
),
want: demangled,
}

var b bytes.Buffer
if err := Generate(&b, tc.rpt, &binutils.Binutils{}); err != nil {
t.Fatalf("%s: %v", tc.want, err)
}

if !(strings.Contains(b.String(), tc.want)) ||
(strings.Contains(b.String(), "_Z")) {
t.Fatalf("want: %s\n got: %s\n", tc.want, string(b.String()))
}
}

func TestDisambiguation(t *testing.T) {
parent1 := &graph.Node{Info: graph.NodeInfo{Name: "parent1"}}
parent2 := &graph.Node{Info: graph.NodeInfo{Name: "parent2"}}
Expand Down
Binary file added internal/report/testdata/disasm.bin
Binary file not shown.
24 changes: 24 additions & 0 deletions internal/report/testdata/sample/disasm.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// sample program that is used to produce some of the files in
// pprof/internal/report/testdata.

#include <iostream>

using namespace std;
int main(int argc, char** argv) {
cout << "Hello World!" << endl;
return 0;
}

0 comments on commit da402b4

Please sign in to comment.