Skip to content

[lldb] Use Function::GetAddress in Module::FindFunctions #124938

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 1 commit into from
Jan 31, 2025

Conversation

labath
Copy link
Collaborator

@labath labath commented Jan 29, 2025

The original code resulted in a misfire in the symtab vs. debug info deduplication code, which caused us to return the same function twice when searching via a regex (for functions whose entry point is also not the lowest address).

The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2025

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

The original code resulted in a misfire in the symtab vs. debug info deduplication code, which caused us to return the same function twice when searching via a regex (for functions whose entry point is also not the lowest address).


Full diff: https://github.com/llvm/llvm-project/pull/124938.diff

2 Files Affected:

  • (modified) lldb/source/Core/Module.cpp (+2-3)
  • (modified) lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s (+16-4)
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 9601c834d9b8fe..33668c5d20dde4 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -919,9 +919,8 @@ void Module::FindFunctions(const RegularExpression &regex,
               const SymbolContext &sc = sc_list[i];
               if (sc.block)
                 continue;
-              file_addr_to_index[sc.function->GetAddressRange()
-                                     .GetBaseAddress()
-                                     .GetFileAddress()] = i;
+              file_addr_to_index[sc.function->GetAddress().GetFileAddress()] =
+                  i;
             }
 
             FileAddrToIndexMap::const_iterator end = file_addr_to_index.end();
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s
index 93ea9f33e762df..197ab9aa14910e 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/discontinuous-function.s
@@ -6,17 +6,29 @@
 # The function bar has been placed "in the middle" of foo, and the function
 # entry point is deliberately not its lowest address.
 
-# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %s -o %t
-# RUN: %lldb %t -o "image lookup -v -n foo" -o "expr -- &foo" -o exit | FileCheck %s
+# RUN: split-file %s %t
+# RUN: llvm-mc -triple x86_64-pc-linux -filetype=obj %t/input.s -o %t/input.o
+# RUN: %lldb %t/input.o -s %t/commands -o exit | FileCheck %s
 
-# CHECK-LABEL: image lookup
+#--- commands
+
+image lookup -v -n foo
+# CHECK-LABEL: image lookup -v -n foo
+# CHECK: 1 match found in {{.*}}
+# CHECK: Summary: input.o`foo
+# CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x0000000000000000-0x000000000000000e)[0x0000000000000014-0x000000000000001c)
+
+image lookup -v --regex -n '^foo$'
+# CHECK-LABEL: image lookup -v --regex -n '^foo$'
 # CHECK: 1 match found in {{.*}}
-# CHECK: Summary: {{.*}}`foo
+# CHECK: Summary: input.o`foo
 # CHECK: Function: id = {{.*}}, name = "foo", ranges = [0x0000000000000000-0x000000000000000e)[0x0000000000000014-0x000000000000001c)
 
+expr -- &foo
 # CHECK-LABEL: expr -- &foo
 # CHECK: (void (*)()) $0 = 0x0000000000000007
 
+#--- input.s
         .text
 
 foo.__part.1:

@jimingham
Copy link
Collaborator

This looks fine, but more generally, is there any good reason to ever use Function::GetAddressRange? Shouldn't that just be removed and all the instances replaced with either GetAddress or get the ranges and iterate over them looking for whatever they wanted?

@labath
Copy link
Collaborator Author

labath commented Jan 30, 2025

There isn't a good reason for using GetAddressRange, and removing it is what I'm trying to do. But rather than trying to do it all at once, I'm doing it in pieces as some of the changes (particularly those that need to iterate over a set of ranges) are not trivial. This way I can also verify that each change does what it's supposed to do.

I changed most of the trivial call sites when I introduced GetAddress (in #115836). In retrospect, this is probably trivial enough that it could have been a part of that, but I skipped it then because the mapping part looked scary.

Copy link
Collaborator

@jimingham jimingham left a comment

Choose a reason for hiding this comment

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

LGTM. You might add a comment to GetAddressRange saying "I'm in the process of getting rid of this, don't use it in the meantime...". But presumably you are also watching PR's to make sure nobody reintroduces its use.

@labath
Copy link
Collaborator Author

labath commented Jan 31, 2025

I added a "DEPRECATED" comment, which isn't quite as strong, but sort of conveys the same thing. The function is called from a bunch of places, but I don't think there's that much churn around it for backsliding to be a problem.

@labath labath merged commit 3736de2 into llvm:main Jan 31, 2025
9 checks passed
@labath labath deleted the lookup branch January 31, 2025 08:13
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Mar 8, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Mar 20, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Apr 2, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Apr 17, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Apr 30, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request May 15, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request May 29, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
SquallATF pushed a commit to SquallATF/llvm-project that referenced this pull request Jun 13, 2025
The original code resulted in a misfire in the symtab vs. debug info
deduplication code, which caused us to return the same function twice
when searching via a regex (for functions whose entry point is also not
the lowest address).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants