proc: do not wipe sources list when a plugin is detected (#2075)

The list of source files must include all files from all images, not
just the files from the last discovered image.

Fixes #2074
This commit is contained in:
Alessandro Arzilli 2020-06-05 20:23:48 +02:00 committed by GitHub
parent a72723433b
commit 708eadd553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

@ -1599,7 +1599,6 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugLineBytes []byte, wg
bi.LookupFunc[bi.Functions[i].Name] = &bi.Functions[i]
}
bi.Sources = []string{}
for _, cu := range image.compileUnits {
if cu.lineInfo != nil {
for _, fileEntry := range cu.lineInfo.FileNames {

@ -4272,10 +4272,23 @@ func TestDeadlockBreakpoint(t *testing.T) {
})
}
func findSource(source string, sources []string) bool {
for _, s := range sources {
if s == source {
return true
}
}
return false
}
func TestListImages(t *testing.T) {
pluginFixtures := protest.WithPlugins(t, protest.AllNonOptimized, "plugin1/", "plugin2/")
withTestProcessArgs("plugintest", t, ".", []string{pluginFixtures[0].Path, pluginFixtures[1].Path}, protest.AllNonOptimized, func(p *proc.Target, fixture protest.Fixture) {
if !findSource(fixture.Source, p.BinInfo().Sources) {
t.Fatalf("could not find %s in sources: %q\n", fixture.Source, p.BinInfo().Sources)
}
assertNoError(p.Continue(), t, "first continue")
f, l := currentLineNumber(p, t)
plugin1Found := false
@ -4289,6 +4302,10 @@ func TestListImages(t *testing.T) {
if !plugin1Found {
t.Fatalf("Could not find plugin1")
}
if !findSource(fixture.Source, p.BinInfo().Sources) {
// Source files for the base program must be available even after a plugin is loaded. Issue #2074.
t.Fatalf("could not find %s in sources (after loading plugin): %q\n", fixture.Source, p.BinInfo().Sources)
}
assertNoError(p.Continue(), t, "second continue")
f, l = currentLineNumber(p, t)
plugin1Found, plugin2Found := false, false