aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2018-04-13 14:52:54 +0000
committerGreg Clayton <gclayton@apple.com>2018-04-13 14:52:54 +0000
commit52098cf5da185732784e417489ed867236b3fe0a (patch)
tree924c40be68a311433929ce9e7f3cbf754bd78fd4 /lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
parent6d086b694383a16f3c501c033ae0c81db8a33136 (diff)
downloadllvm-52098cf5da185732784e417489ed867236b3fe0a.zip
llvm-52098cf5da185732784e417489ed867236b3fe0a.tar.gz
llvm-52098cf5da185732784e417489ed867236b3fe0a.tar.bz2
Allow relative file paths when settings source breakpoints
Many IDEs set breakpoints using absolute paths and this causes problems when the full path of the source file path doesn't match what is in the debug info. This can be due to different build systems and do or do not resolve symlinks. This patch allows relative breakpoint to be set correctly without needing to do any target.source-map tricks. If IDEs want to, they can send down relative paths like: ./main.c ./src/main.c src/main.c foo/bar/src/main.c I used the breakpoint resolver to match on the file basename and then we weed out anything whose relative paths don't match. This will be a huge improvement for IDEs as they can specify as much of a relative path as desired to uniquely identify a source file in the current project. Differential Revision: https://reviews.llvm.org/D45592 llvm-svn: 330028
Diffstat (limited to 'lldb/source/Breakpoint/BreakpointResolverFileLine.cpp')
-rw-r--r--lldb/source/Breakpoint/BreakpointResolverFileLine.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
index 780d25d..feef9e7 100644
--- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
@@ -115,15 +115,35 @@ BreakpointResolverFileLine::SerializeToStructuredData() {
// here is handling inlined functions -- in this case we need to make sure we
// look at the declaration line of the inlined function, NOT the function it was
// inlined into.
-void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list) {
+void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list,
+ bool is_relative) {
if (m_exact_match)
return; // Nothing to do. Contexts are precise.
+ llvm::StringRef relative_path;
+ if (is_relative)
+ relative_path = m_file_spec.GetNormalizedPath().GetDirectory().GetStringRef();
+
Log * log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
for(uint32_t i = 0; i < sc_list.GetSize(); ++i) {
SymbolContext sc;
sc_list.GetContextAtIndex(i, sc);
- if (! sc.block)
+ if (is_relative) {
+ // If the path was relative, make sure any matches match as long as the
+ // relative parts of the path match the path from support files
+ auto sc_dir = sc.line_entry.file.GetDirectory().GetStringRef();
+ if (!sc_dir.endswith(relative_path)) {
+ // We had a relative path specified and the relative directory
+ // doesn't match so remove this one
+ LLDB_LOG(log, "removing not matching relative path {0} since it "
+ "doesn't end with {1}", sc_dir, relative_path);
+ sc_list.RemoveContextAtIndex(i);
+ --i;
+ continue;
+ }
+ }
+
+ if (!sc.block)
continue;
FileSpec file;
@@ -194,18 +214,23 @@ BreakpointResolverFileLine::SearchCallback(SearchFilter &filter,
// through the match list and pull out the sets that have the same file spec
// in their line_entry and treat each set separately.
+ FileSpec search_file_spec = m_file_spec;
+ const bool is_relative = m_file_spec.IsRelative();
+ if (is_relative)
+ search_file_spec.GetDirectory().Clear();
+
const size_t num_comp_units = context.module_sp->GetNumCompileUnits();
for (size_t i = 0; i < num_comp_units; i++) {
CompUnitSP cu_sp(context.module_sp->GetCompileUnitAtIndex(i));
if (cu_sp) {
if (filter.CompUnitPasses(*cu_sp))
- cu_sp->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines,
+ cu_sp->ResolveSymbolContext(search_file_spec, m_line_number, m_inlines,
m_exact_match, eSymbolContextEverything,
sc_list);
}
}
- FilterContexts(sc_list);
+ FilterContexts(sc_list, is_relative);
StreamString s;
s.Printf("for %s:%d ", m_file_spec.GetFilename().AsCString("<Unknown>"),