Skip to content

Fix a thinko in the CallSite handling code: #114896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lldb/source/Symbol/CompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,17 @@ void CompileUnit::ResolveSymbolContext(
// We will miss functions that ONLY exist as a call site entry.

if (line_entry.IsValid() &&
(line_entry.line != line || line_entry.column != column_num) &&
resolve_scope & eSymbolContextLineEntry && check_inlines) {
(line_entry.line != line ||
(column_num != 0 && line_entry.column != column_num)) &&
(resolve_scope & eSymbolContextLineEntry) && check_inlines) {
// We don't move lines over function boundaries, so the address in the
// line entry will be the in function that contained the line that might
// be a CallSite, and we can just iterate over that function to find any
// inline records, and dig up their call sites.
Address start_addr = line_entry.range.GetBaseAddress();
Function *function = start_addr.CalculateSymbolContextFunction();
// Record the size of the list to see if we added to it:
size_t old_sc_list_size = sc_list.GetSize();

Declaration sought_decl(file_spec, line, column_num);
// We use this recursive function to descend the block structure looking
Expand Down Expand Up @@ -417,7 +420,7 @@ void CompileUnit::ResolveSymbolContext(
// FIXME: Should I also do this for "call site line exists between the
// given line number and the later line we found in the line table"? That's
// a closer approximation to our general sliding algorithm.
if (sc_list.GetSize())
if (sc_list.GetSize() > old_sc_list_size)
return;
}

Expand Down
19 changes: 19 additions & 0 deletions lldb/test/API/functionalities/breakpoint/same_cu_name/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CXX_SOURCES := main.cpp
LD_EXTRAS := ns1.o ns2.o ns3.o ns4.o

a.out: main.o ns1.o ns2.o ns3.o ns4.o

ns1.o: common.cpp
$(CC) -g -c -DNAMESPACE=ns1 -o $@ $<

ns2.o: common.cpp
$(CC) -g -c -DNAMESPACE=ns2 -o $@ $<

ns3.o: common.cpp
$(CC) -g -c -DNAMESPACE=ns3 -o $@ $<

ns4.o: common.cpp
$(CC) -g -c -DNAMESPACE=ns4 -o $@ $<


include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Test setting a breakpoint by file and line when many instances of the
same file name exist in the CU list.
"""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class TestBreakpointSameCU(TestBase):
def test_breakpoint_same_cu(self):
self.build()
target = self.createTestTarget()

# Break both on the line before the code:
comment_line = line_number("common.cpp", "// A comment here")
self.assertNotEqual(comment_line, 0, "line_number worked")
bkpt = target.BreakpointCreateByLocation("common.cpp", comment_line)
self.assertEqual(
bkpt.GetNumLocations(), 4, "Got the right number of breakpoints"
)

# And break on the code, both should work:
code_line = line_number("common.cpp", "// The line with code")
self.assertNotEqual(comment_line, 0, "line_number worked again")
bkpt = target.BreakpointCreateByLocation("common.cpp", code_line)
self.assertEqual(
bkpt.GetNumLocations(), 4, "Got the right number of breakpoints"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace NAMESPACE {
static int g_value = 0;
void DoSomeStuff() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: inconsistent indentation.

// A comment here
g_value++; // The line with code
}

} // namespace NAMESPACE
24 changes: 24 additions & 0 deletions lldb/test/API/functionalities/breakpoint/same_cu_name/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ns1 {
extern void DoSomeStuff();
}

namespace ns2 {
extern void DoSomeStuff();
}

namespace ns3 {
extern void DoSomeStuff();
}

namespace ns4 {
extern void DoSomeStuff();
}

int main(int argc, char *argv[]) {
ns1::DoSomeStuff();
ns2::DoSomeStuff();
ns3::DoSomeStuff();
ns4::DoSomeStuff();

return 0;
}
Loading