[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- BreakpointResolverFileLine.cpp ------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// BreakpointResolverFileLine:
|
|
|
|
BreakpointResolverFileLine::BreakpointResolverFileLine(
|
2021-05-05 07:03:10 +08:00
|
|
|
const BreakpointSP &bkpt, lldb::addr_t offset, bool skip_prologue,
|
|
|
|
const SourceLocationSpec &location_spec)
|
2016-03-10 02:59:13 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::FileLineResolver, offset),
|
2021-05-05 07:03:10 +08:00
|
|
|
m_location_spec(location_spec), m_skip_prologue(skip_prologue) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
BreakpointResolver *BreakpointResolverFileLine::CreateFromStructuredData(
|
2020-03-03 18:29:12 +08:00
|
|
|
const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
|
2017-05-12 12:51:55 +08:00
|
|
|
Status &error) {
|
2017-05-12 13:49:54 +08:00
|
|
|
llvm::StringRef filename;
|
2021-05-05 07:03:10 +08:00
|
|
|
uint32_t line;
|
|
|
|
uint16_t column;
|
2016-09-13 07:10:56 +08:00
|
|
|
bool check_inlines;
|
|
|
|
bool skip_prologue;
|
|
|
|
bool exact_match;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
lldb::addr_t offset = 0;
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsString(GetKey(OptionNames::FileName),
|
|
|
|
filename);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find filename entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsInteger(
|
2021-05-05 07:03:10 +08:00
|
|
|
GetKey(OptionNames::LineNumber), line);
|
2016-09-13 07:10:56 +08:00
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find line number entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-30 23:11:00 +08:00
|
|
|
success =
|
|
|
|
options_dict.GetValueForKeyAsInteger(GetKey(OptionNames::Column), column);
|
|
|
|
if (!success) {
|
|
|
|
// Backwards compatibility.
|
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
|
2016-09-13 07:10:56 +08:00
|
|
|
success = options_dict.GetValueForKeyAsBoolean(GetKey(OptionNames::Inlines),
|
|
|
|
check_inlines);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find check inlines entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsBoolean(
|
|
|
|
GetKey(OptionNames::SkipPrologue), skip_prologue);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find skip prologue entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsBoolean(
|
|
|
|
GetKey(OptionNames::ExactMatch), exact_match);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find exact match entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-05-05 07:03:10 +08:00
|
|
|
SourceLocationSpec location_spec(FileSpec(filename), line, column,
|
|
|
|
check_inlines, exact_match);
|
|
|
|
if (!location_spec)
|
|
|
|
return nullptr;
|
2016-09-13 07:10:56 +08:00
|
|
|
|
2021-05-05 07:03:10 +08:00
|
|
|
return new BreakpointResolverFileLine(bkpt, offset, skip_prologue,
|
|
|
|
location_spec);
|
2016-09-13 07:10:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP
|
|
|
|
BreakpointResolverFileLine::SerializeToStructuredData() {
|
|
|
|
StructuredData::DictionarySP options_dict_sp(
|
|
|
|
new StructuredData::Dictionary());
|
|
|
|
|
|
|
|
options_dict_sp->AddBooleanItem(GetKey(OptionNames::SkipPrologue),
|
|
|
|
m_skip_prologue);
|
2021-05-05 07:03:10 +08:00
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::FileName),
|
|
|
|
m_location_spec.GetFileSpec().GetPath());
|
|
|
|
options_dict_sp->AddIntegerItem(GetKey(OptionNames::LineNumber),
|
|
|
|
m_location_spec.GetLine().getValueOr(0));
|
|
|
|
options_dict_sp->AddIntegerItem(
|
|
|
|
GetKey(OptionNames::Column),
|
|
|
|
m_location_spec.GetColumn().getValueOr(LLDB_INVALID_COLUMN_NUMBER));
|
|
|
|
options_dict_sp->AddBooleanItem(GetKey(OptionNames::Inlines),
|
|
|
|
m_location_spec.GetCheckInlines());
|
2016-09-13 07:10:56 +08:00
|
|
|
options_dict_sp->AddBooleanItem(GetKey(OptionNames::ExactMatch),
|
2021-05-05 07:03:10 +08:00
|
|
|
m_location_spec.GetExactMatch());
|
2016-09-13 07:10:56 +08:00
|
|
|
|
|
|
|
return WrapOptionsDict(options_dict_sp);
|
|
|
|
}
|
|
|
|
|
2017-03-15 17:53:10 +08:00
|
|
|
// Filter the symbol context list to remove contexts where the line number was
|
|
|
|
// moved into a new function. We do this conservatively, so if e.g. we cannot
|
2018-05-01 00:49:04 +08:00
|
|
|
// resolve the function in the context (which can happen in case of line-table-
|
|
|
|
// only debug info), we leave the context as is. The trickiest part 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
|
2017-03-15 17:53:10 +08:00
|
|
|
// inlined into.
|
2018-04-13 22:52:54 +08:00
|
|
|
void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list,
|
|
|
|
bool is_relative) {
|
2021-05-05 07:03:10 +08:00
|
|
|
if (m_location_spec.GetExactMatch())
|
2017-03-15 17:53:10 +08:00
|
|
|
return; // Nothing to do. Contexts are precise.
|
|
|
|
|
2018-04-13 22:52:54 +08:00
|
|
|
llvm::StringRef relative_path;
|
|
|
|
if (is_relative)
|
2021-05-05 07:03:10 +08:00
|
|
|
relative_path = m_location_spec.GetFileSpec().GetDirectory().GetStringRef();
|
2018-04-13 22:52:54 +08:00
|
|
|
|
2022-01-31 22:57:48 +08:00
|
|
|
Log *log = GetLog(LLDBLog::Breakpoints);
|
2017-03-15 17:53:10 +08:00
|
|
|
for(uint32_t i = 0; i < sc_list.GetSize(); ++i) {
|
|
|
|
SymbolContext sc;
|
|
|
|
sc_list.GetContextAtIndex(i, sc);
|
2018-04-13 22:52:54 +08:00
|
|
|
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)) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We had a relative path specified and the relative directory doesn't
|
|
|
|
// match so remove this one
|
2018-04-13 22:52:54 +08:00
|
|
|
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)
|
2017-03-15 17:53:10 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
FileSpec file;
|
|
|
|
uint32_t line;
|
|
|
|
const Block *inline_block = sc.block->GetContainingInlinedBlock();
|
|
|
|
if (inline_block) {
|
|
|
|
const Declaration &inline_declaration = inline_block->GetInlinedFunctionInfo()->GetDeclaration();
|
|
|
|
if (!inline_declaration.IsValid())
|
|
|
|
continue;
|
|
|
|
file = inline_declaration.GetFile();
|
|
|
|
line = inline_declaration.GetLine();
|
|
|
|
} else if (sc.function)
|
|
|
|
sc.function->GetStartLineSourceInfo(file, line);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (file != sc.line_entry.file) {
|
|
|
|
LLDB_LOG(log, "unexpected symbol context file {0}", sc.line_entry.file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare the requested line number with the line of the function
|
|
|
|
// declaration. In case of a function declared as:
|
|
|
|
//
|
|
|
|
// int
|
|
|
|
// foo()
|
|
|
|
// {
|
|
|
|
// ...
|
|
|
|
//
|
|
|
|
// the compiler will set the declaration line to the "foo" line, which is
|
|
|
|
// the reason why we have -1 here. This can fail in case of two inline
|
|
|
|
// functions defined back-to-back:
|
|
|
|
//
|
|
|
|
// inline int foo1() { ... }
|
|
|
|
// inline int foo2() { ... }
|
|
|
|
//
|
|
|
|
// but that's the best we can do for now.
|
2018-08-08 05:09:55 +08:00
|
|
|
// One complication, if the line number returned from GetStartLineSourceInfo
|
|
|
|
// is 0, then we can't do this calculation. That can happen if
|
|
|
|
// GetStartLineSourceInfo gets an error, or if the first line number in
|
|
|
|
// the function really is 0 - which happens for some languages.
|
2021-07-30 09:14:34 +08:00
|
|
|
|
2021-01-21 09:58:34 +08:00
|
|
|
// But only do this calculation if the line number we found in the SC
|
|
|
|
// was different from the one requested in the source file. If we actually
|
|
|
|
// found an exact match it must be valid.
|
2021-05-05 07:03:10 +08:00
|
|
|
|
|
|
|
if (m_location_spec.GetLine() == sc.line_entry.line)
|
2021-01-21 09:58:34 +08:00
|
|
|
continue;
|
|
|
|
|
2017-03-15 17:53:10 +08:00
|
|
|
const int decl_line_is_too_late_fudge = 1;
|
2021-05-05 07:03:10 +08:00
|
|
|
if (line &&
|
|
|
|
m_location_spec.GetLine() < line - decl_line_is_too_late_fudge) {
|
2017-03-15 17:53:10 +08:00
|
|
|
LLDB_LOG(log, "removing symbol context at {0}:{1}", file, line);
|
|
|
|
sc_list.RemoveContextAtIndex(i);
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 19:26:51 +08:00
|
|
|
Searcher::CallbackReturn BreakpointResolverFileLine::SearchCallback(
|
|
|
|
SearchFilter &filter, SymbolContext &context, Address *addr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolContextList sc_list;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-01-13 10:04:05 +08:00
|
|
|
// There is a tricky bit here. You can have two compilation units that
|
2018-05-01 00:49:04 +08:00
|
|
|
// #include the same file, and in one of them the function at m_line_number
|
|
|
|
// is used (and so code and a line entry for it is generated) but in the
|
|
|
|
// other it isn't. If we considered the CU's independently, then in the
|
|
|
|
// second inclusion, we'd move the breakpoint to the next function that
|
|
|
|
// actually generated code in the header file. That would end up being
|
|
|
|
// confusing. So instead, we do the CU iterations by hand here, then scan
|
|
|
|
// through the complete list of matches, and figure out the closest line
|
|
|
|
// number match, and only set breakpoints on that match.
|
|
|
|
|
|
|
|
// Note also that if file_spec only had a file name and not a directory,
|
|
|
|
// there may be many different file spec's in the resultant list. The
|
|
|
|
// closest line match for one will not be right for some totally different
|
|
|
|
// file. So we go through the match list and pull out the sets that have the
|
|
|
|
// same file spec in their line_entry and treat each set separately.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-05-05 07:03:10 +08:00
|
|
|
const uint32_t line = m_location_spec.GetLine().getValueOr(0);
|
|
|
|
const llvm::Optional<uint16_t> column = m_location_spec.GetColumn();
|
|
|
|
|
2021-07-30 09:14:34 +08:00
|
|
|
// We'll create a new SourceLocationSpec that can take into account the
|
|
|
|
// relative path case, and we'll use it to resolve the symbol context
|
|
|
|
// of the CUs.
|
2021-05-05 07:03:10 +08:00
|
|
|
FileSpec search_file_spec = m_location_spec.GetFileSpec();
|
|
|
|
const bool is_relative = search_file_spec.IsRelative();
|
2018-04-13 22:52:54 +08:00
|
|
|
if (is_relative)
|
|
|
|
search_file_spec.GetDirectory().Clear();
|
2021-07-30 09:14:34 +08:00
|
|
|
SourceLocationSpec search_location_spec(
|
|
|
|
search_file_spec, m_location_spec.GetLine().getValueOr(0),
|
|
|
|
m_location_spec.GetColumn(), m_location_spec.GetCheckInlines(),
|
|
|
|
m_location_spec.GetExactMatch());
|
2018-04-13 22:52:54 +08:00
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
const size_t num_comp_units = context.module_sp->GetNumCompileUnits();
|
|
|
|
for (size_t i = 0; i < num_comp_units; i++) {
|
2012-01-13 10:04:05 +08:00
|
|
|
CompUnitSP cu_sp(context.module_sp->GetCompileUnitAtIndex(i));
|
2012-04-24 06:00:21 +08:00
|
|
|
if (cu_sp) {
|
|
|
|
if (filter.CompUnitPasses(*cu_sp))
|
2021-07-30 09:14:34 +08:00
|
|
|
cu_sp->ResolveSymbolContext(search_location_spec,
|
|
|
|
eSymbolContextEverything, sc_list);
|
2012-01-13 10:04:05 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2017-03-15 17:53:10 +08:00
|
|
|
|
2018-04-13 22:52:54 +08:00
|
|
|
FilterContexts(sc_list, is_relative);
|
2017-03-15 17:53:10 +08:00
|
|
|
|
2013-09-27 09:16:58 +08:00
|
|
|
StreamString s;
|
2021-05-05 07:03:10 +08:00
|
|
|
s.Printf("for %s:%d ",
|
|
|
|
m_location_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"),
|
|
|
|
line);
|
2013-09-27 09:16:58 +08:00
|
|
|
|
2021-05-05 07:03:10 +08:00
|
|
|
SetSCMatchesByLine(filter, sc_list, m_skip_prologue, s.GetString(), line,
|
|
|
|
column);
|
2012-01-13 10:04:05 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return Searcher::eCallbackReturnContinue;
|
|
|
|
}
|
|
|
|
|
2018-09-08 02:43:04 +08:00
|
|
|
lldb::SearchDepth BreakpointResolverFileLine::GetDepth() {
|
|
|
|
return lldb::eSearchDepthModule;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverFileLine::GetDescription(Stream *s) {
|
2021-05-05 07:03:10 +08:00
|
|
|
s->Printf("file = '%s', line = %u, ",
|
|
|
|
m_location_spec.GetFileSpec().GetPath().c_str(),
|
|
|
|
m_location_spec.GetLine().getValueOr(0));
|
|
|
|
auto column = m_location_spec.GetColumn();
|
|
|
|
if (column)
|
|
|
|
s->Printf("column = %u, ", *column);
|
|
|
|
s->Printf("exact_match = %d", m_location_spec.GetExactMatch());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverFileLine::Dump(Stream *s) const {}
|
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::BreakpointResolverSP
|
2020-03-03 18:29:12 +08:00
|
|
|
BreakpointResolverFileLine::CopyForBreakpoint(BreakpointSP &breakpoint) {
|
2014-12-06 09:28:03 +08:00
|
|
|
lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileLine(
|
2021-05-05 07:03:10 +08:00
|
|
|
breakpoint, GetOffset(), m_skip_prologue, m_location_spec));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-06 09:28:03 +08:00
|
|
|
return ret_sp;
|
|
|
|
}
|