[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 08:23:27 +01:00
|
|
|
//===-- CommandObjectSource.cpp -------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "CommandObjectSource.h"
|
|
|
|
|
|
2010-06-23 01:19:29 +00:00
|
|
|
#include "lldb/Core/Debugger.h"
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
#include "lldb/Core/FileLineResolver.h"
|
2012-12-07 00:19:47 +00:00
|
|
|
#include "lldb/Core/Module.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-29 21:13:06 +00:00
|
|
|
#include "lldb/Core/ModuleSpec.h"
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
#include "lldb/Core/SourceManager.h"
|
2017-03-22 23:33:16 +00:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2022-07-13 20:11:37 -07:00
|
|
|
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2018-04-10 09:03:59 +00:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2020-07-16 11:34:50 -07:00
|
|
|
#include "lldb/Interpreter/OptionValueFileColonLine.h"
|
2010-07-07 03:36:20 +00:00
|
|
|
#include "lldb/Interpreter/Options.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-29 21:13:06 +00:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
|
#include "lldb/Symbol/Function.h"
|
2013-07-11 16:40:56 +00:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:
1. We always resolve the path.
2. We always check the timestamp.
3. We always recheck the file system for negative cache hits.
D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.
We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:
- The cache at the debugger level works the way it does today. There is
no negative cache: if we can't find the file on disk, we'll try again
next time the cache is queried. If a cached file's timestamp changes
or if its path remapping changes, the cached file is evicted and we
reload it from disk.
- The cache at the process level is design to avoid accessing the file
system. It doesn't check the file's modification time. It caches
negative results, so if a file didn't exist, it doesn't try to reread
it from disk. Checking if the path remapping changed is cheap
(doesn't involve checking the file system) and is the only way for a
file to get evicted from the process cache.
The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.
For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.
In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.
rdar://110787562
Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:06:57 -07:00
|
|
|
#include "lldb/Target/Process.h"
|
2013-12-06 01:12:00 +00:00
|
|
|
#include "lldb/Target/SectionLoadList.h"
|
2016-01-05 19:51:51 +00:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2017-03-22 18:40:07 +00:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2023-01-07 13:43:00 -08:00
|
|
|
#include <optional>
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
#pragma mark CommandObjectSourceInfo
|
|
|
|
|
// CommandObjectSourceInfo - debug line entries dumping command
|
2019-07-23 11:08:12 +00:00
|
|
|
#define LLDB_OPTIONS_source_info
|
|
|
|
|
#include "CommandOptions.inc"
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectSourceInfo : public CommandObjectParsed {
|
2010-07-07 03:36:20 +00:00
|
|
|
class CommandOptions : public Options {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-24 02:05:55 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
const int short_option = GetDefinitions()[option_idx].short_option;
|
2010-07-07 03:36:20 +00:00
|
|
|
switch (short_option) {
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'l':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (option_arg.getAsInteger(0, start_line))
|
2016-01-05 19:51:51 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid line number: '%s'",
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg.str().c_str());
|
2016-01-05 19:51:51 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'e':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (option_arg.getAsInteger(0, end_line))
|
2016-01-05 19:51:51 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid line number: '%s'",
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg.str().c_str());
|
2016-01-05 19:51:51 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'c':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (option_arg.getAsInteger(0, num_lines))
|
2016-01-05 19:51:51 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid line count: '%s'",
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg.str().c_str());
|
2016-01-05 19:51:51 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'f':
|
2020-01-28 20:23:46 +01:00
|
|
|
file_name = std::string(option_arg);
|
2016-01-05 19:51:51 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'n':
|
2020-01-28 20:23:46 +01:00
|
|
|
symbol_name = std::string(option_arg);
|
2016-01-05 19:51:51 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
case 'a': {
|
2018-04-10 09:03:59 +00:00
|
|
|
address = OptionArgParser::ToAddress(execution_context, option_arg,
|
|
|
|
|
LLDB_INVALID_ADDRESS, &error);
|
2010-07-07 03:36:20 +00:00
|
|
|
} break;
|
2016-01-05 19:51:51 +00:00
|
|
|
case 's':
|
|
|
|
|
modules.push_back(std::string(option_arg));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2010-07-07 03:36:20 +00:00
|
|
|
file_spec.Clear();
|
|
|
|
|
file_name.clear();
|
2016-01-05 19:51:51 +00:00
|
|
|
symbol_name.clear();
|
|
|
|
|
address = LLDB_INVALID_ADDRESS;
|
2010-07-07 03:36:20 +00:00
|
|
|
start_line = 0;
|
2016-01-05 19:51:51 +00:00
|
|
|
end_line = 0;
|
|
|
|
|
num_lines = 0;
|
|
|
|
|
modules.clear();
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_source_info_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
|
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
|
FileSpec file_spec;
|
|
|
|
|
std::string file_name;
|
2016-01-05 19:51:51 +00:00
|
|
|
std::string symbol_name;
|
|
|
|
|
lldb::addr_t address;
|
2010-07-07 03:36:20 +00:00
|
|
|
uint32_t start_line;
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t end_line;
|
|
|
|
|
uint32_t num_lines;
|
2019-11-06 14:44:39 -08:00
|
|
|
std::vector<std::string> modules;
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
public:
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectSourceInfo(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(
|
|
|
|
|
interpreter, "source info",
|
|
|
|
|
"Display source line information for the current target "
|
|
|
|
|
"process. Defaults to instruction pointer in current stack "
|
|
|
|
|
"frame.",
|
2022-01-23 11:07:14 -08:00
|
|
|
nullptr, eCommandRequiresTarget) {}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2016-02-24 02:05:55 +00:00
|
|
|
~CommandObjectSourceInfo() override = default;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2018-04-30 16:49:04 +00:00
|
|
|
// Dump the line entries in each symbol context. Return the number of entries
|
|
|
|
|
// found. If module_list is set, only dump lines contained in one of the
|
|
|
|
|
// modules. If file_spec is set, only dump lines in the file. If the
|
|
|
|
|
// start_line option was specified, don't print lines less than start_line.
|
2016-01-05 19:51:51 +00:00
|
|
|
// If the end_line option was specified, don't print lines greater than
|
2018-04-30 16:49:04 +00:00
|
|
|
// end_line. If the num_lines option was specified, dont print more than
|
|
|
|
|
// num_lines entries.
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t DumpLinesInSymbolContexts(Stream &strm,
|
|
|
|
|
const SymbolContextList &sc_list,
|
|
|
|
|
const ModuleList &module_list,
|
|
|
|
|
const FileSpec &file_spec) {
|
|
|
|
|
uint32_t start_line = m_options.start_line;
|
|
|
|
|
uint32_t end_line = m_options.end_line;
|
|
|
|
|
uint32_t num_lines = m_options.num_lines;
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t num_matches = 0;
|
|
|
|
|
// Dump all the line entries for the file in the list.
|
|
|
|
|
ConstString last_module_file_name;
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list) {
|
2016-01-05 19:51:51 +00:00
|
|
|
if (sc.comp_unit) {
|
|
|
|
|
Module *module = sc.module_sp.get();
|
|
|
|
|
CompileUnit *cu = sc.comp_unit;
|
|
|
|
|
const LineEntry &line_entry = sc.line_entry;
|
|
|
|
|
assert(module && cu);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Are we looking for specific modules, files or lines?
|
|
|
|
|
if (module_list.GetSize() &&
|
|
|
|
|
module_list.GetIndexForModule(module) == LLDB_INVALID_INDEX32)
|
|
|
|
|
continue;
|
2024-03-21 08:40:08 -07:00
|
|
|
if (!FileSpec::Match(file_spec, line_entry.GetFile()))
|
2016-01-05 19:51:51 +00:00
|
|
|
continue;
|
|
|
|
|
if (start_line > 0 && line_entry.line < start_line)
|
|
|
|
|
continue;
|
|
|
|
|
if (end_line > 0 && line_entry.line > end_line)
|
|
|
|
|
continue;
|
|
|
|
|
if (num_lines > 0 && num_matches > num_lines)
|
|
|
|
|
continue;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Print a new header if the module changed.
|
2019-10-30 15:26:19 -07:00
|
|
|
ConstString module_file_name = module->GetFileSpec().GetFilename();
|
2016-01-05 19:51:51 +00:00
|
|
|
assert(module_file_name);
|
|
|
|
|
if (module_file_name != last_module_file_name) {
|
|
|
|
|
if (num_matches > 0)
|
|
|
|
|
strm << "\n\n";
|
|
|
|
|
strm << "Lines found in module `" << module_file_name << "\n";
|
|
|
|
|
}
|
|
|
|
|
// Dump the line entry.
|
|
|
|
|
line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu,
|
|
|
|
|
target, /*show_address_only=*/false);
|
|
|
|
|
strm << "\n";
|
|
|
|
|
last_module_file_name = module_file_name;
|
|
|
|
|
num_matches++;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
|
|
|
|
return num_matches;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Dump the requested line entries for the file in the compilation unit.
|
2018-04-30 16:49:04 +00:00
|
|
|
// Return the number of entries found. If module_list is set, only dump lines
|
|
|
|
|
// contained in one of the modules. If the start_line option was specified,
|
|
|
|
|
// don't print lines less than start_line. If the end_line option was
|
|
|
|
|
// specified, don't print lines greater than end_line. If the num_lines
|
|
|
|
|
// option was specified, dont print more than num_lines entries.
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t DumpFileLinesInCompUnit(Stream &strm, Module *module,
|
|
|
|
|
CompileUnit *cu, const FileSpec &file_spec) {
|
|
|
|
|
uint32_t start_line = m_options.start_line;
|
|
|
|
|
uint32_t end_line = m_options.end_line;
|
|
|
|
|
uint32_t num_lines = m_options.num_lines;
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t num_matches = 0;
|
|
|
|
|
assert(module);
|
|
|
|
|
if (cu) {
|
|
|
|
|
assert(file_spec.GetFilename().AsCString());
|
|
|
|
|
bool has_path = (file_spec.GetDirectory().AsCString() != nullptr);
|
2024-01-04 09:04:05 -08:00
|
|
|
const SupportFileList &cu_file_list = cu->GetSupportFiles();
|
2016-01-05 19:51:51 +00:00
|
|
|
size_t file_idx = cu_file_list.FindFileIndex(0, file_spec, has_path);
|
|
|
|
|
if (file_idx != UINT32_MAX) {
|
|
|
|
|
// Update the file to how it appears in the CU.
|
|
|
|
|
const FileSpec &cu_file_spec =
|
|
|
|
|
cu_file_list.GetFileSpecAtIndex(file_idx);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Dump all matching lines at or above start_line for the file in the
|
2016-09-06 20:57:50 +00:00
|
|
|
// CU.
|
2019-03-06 21:22:25 +00:00
|
|
|
ConstString file_spec_name = file_spec.GetFilename();
|
2019-10-30 15:26:19 -07:00
|
|
|
ConstString module_file_name = module->GetFileSpec().GetFilename();
|
2016-01-05 19:51:51 +00:00
|
|
|
bool cu_header_printed = false;
|
|
|
|
|
uint32_t line = start_line;
|
|
|
|
|
while (true) {
|
|
|
|
|
LineEntry line_entry;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Find the lowest index of a line entry with a line equal to or
|
|
|
|
|
// higher than 'line'.
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t start_idx = 0;
|
|
|
|
|
start_idx = cu->FindLineEntry(start_idx, line, &cu_file_spec,
|
|
|
|
|
/*exact=*/false, &line_entry);
|
|
|
|
|
if (start_idx == UINT32_MAX)
|
|
|
|
|
// No more line entries for our file in this CU.
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
if (end_line > 0 && line_entry.line > end_line)
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Loop through to find any other entries for this line, dumping
|
|
|
|
|
// each.
|
2016-01-05 19:51:51 +00:00
|
|
|
line = line_entry.line;
|
|
|
|
|
do {
|
|
|
|
|
num_matches++;
|
|
|
|
|
if (num_lines > 0 && num_matches > num_lines)
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2024-03-21 08:40:08 -07:00
|
|
|
assert(cu_file_spec == line_entry.GetFile());
|
2016-01-05 19:51:51 +00:00
|
|
|
if (!cu_header_printed) {
|
|
|
|
|
if (num_matches > 0)
|
|
|
|
|
strm << "\n\n";
|
|
|
|
|
strm << "Lines found for file " << file_spec_name
|
2019-11-28 16:22:44 +01:00
|
|
|
<< " in compilation unit "
|
|
|
|
|
<< cu->GetPrimaryFile().GetFilename() << " in `"
|
2016-01-05 19:51:51 +00:00
|
|
|
<< module_file_name << "\n";
|
|
|
|
|
cu_header_printed = true;
|
|
|
|
|
}
|
|
|
|
|
line_entry.GetDescription(&strm, lldb::eDescriptionLevelBrief, cu,
|
|
|
|
|
target, /*show_address_only=*/false);
|
|
|
|
|
strm << "\n";
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Anymore after this one?
|
|
|
|
|
start_idx++;
|
|
|
|
|
start_idx = cu->FindLineEntry(start_idx, line, &cu_file_spec,
|
|
|
|
|
/*exact=*/true, &line_entry);
|
|
|
|
|
} while (start_idx != UINT32_MAX);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Try the next higher line, starting over at start_idx 0.
|
2016-09-06 20:57:50 +00:00
|
|
|
line++;
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
|
|
|
|
return num_matches;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Dump the requested line entries for the file in the module. Return the
|
|
|
|
|
// number of entries found. If module_list is set, only dump lines contained
|
|
|
|
|
// in one of the modules. If the start_line option was specified, don't print
|
|
|
|
|
// lines less than start_line. If the end_line option was specified, don't
|
|
|
|
|
// print lines greater than end_line. If the num_lines option was specified,
|
|
|
|
|
// dont print more than num_lines entries.
|
2016-01-05 19:51:51 +00:00
|
|
|
uint32_t DumpFileLinesInModule(Stream &strm, Module *module,
|
|
|
|
|
const FileSpec &file_spec) {
|
|
|
|
|
uint32_t num_matches = 0;
|
|
|
|
|
if (module) {
|
|
|
|
|
// Look through all the compilation units (CUs) in this module for ones
|
2018-04-30 16:49:04 +00:00
|
|
|
// that contain lines of code from this source file.
|
2016-01-05 19:51:51 +00:00
|
|
|
for (size_t i = 0; i < module->GetNumCompileUnits(); i++) {
|
|
|
|
|
// Look for a matching source file in this CU.
|
|
|
|
|
CompUnitSP cu_sp(module->GetCompileUnitAtIndex(i));
|
|
|
|
|
if (cu_sp) {
|
2016-02-24 02:05:55 +00:00
|
|
|
num_matches +=
|
|
|
|
|
DumpFileLinesInCompUnit(strm, module, cu_sp.get(), file_spec);
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
|
|
|
|
return num_matches;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Given an address and a list of modules, append the symbol contexts of all
|
2018-04-30 16:49:04 +00:00
|
|
|
// line entries containing the address found in the modules and return the
|
|
|
|
|
// count of matches. If none is found, return an error in 'error_strm'.
|
2016-01-05 19:51:51 +00:00
|
|
|
size_t GetSymbolContextsForAddress(const ModuleList &module_list,
|
|
|
|
|
lldb::addr_t addr,
|
|
|
|
|
SymbolContextList &sc_list,
|
|
|
|
|
StreamString &error_strm) {
|
|
|
|
|
Address so_addr;
|
|
|
|
|
size_t num_matches = 0;
|
|
|
|
|
assert(module_list.GetSize() > 0);
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
|
|
|
|
if (target->GetSectionLoadList().IsEmpty()) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// The target isn't loaded yet, we need to lookup the file address in all
|
|
|
|
|
// modules. Note: the module list option does not apply to addresses.
|
2016-01-05 19:51:51 +00:00
|
|
|
const size_t num_modules = module_list.GetSize();
|
|
|
|
|
for (size_t i = 0; i < num_modules; ++i) {
|
|
|
|
|
ModuleSP module_sp(module_list.GetModuleAtIndex(i));
|
|
|
|
|
if (!module_sp)
|
|
|
|
|
continue;
|
|
|
|
|
if (module_sp->ResolveFileAddress(addr, so_addr)) {
|
|
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.Clear(true);
|
|
|
|
|
if (module_sp->ResolveSymbolContextForAddress(
|
|
|
|
|
so_addr, eSymbolContextEverything, sc) &
|
|
|
|
|
eSymbolContextLineEntry) {
|
|
|
|
|
sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
|
|
|
|
|
++num_matches;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (num_matches == 0)
|
|
|
|
|
error_strm.Printf("Source information for file address 0x%" PRIx64
|
|
|
|
|
" not found in any modules.\n",
|
|
|
|
|
addr);
|
|
|
|
|
} else {
|
2018-04-30 16:49:04 +00:00
|
|
|
// The target has some things loaded, resolve this address to a compile
|
|
|
|
|
// unit + file + line and display
|
2016-01-05 19:51:51 +00:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
|
|
|
|
|
ModuleSP module_sp(so_addr.GetModule());
|
|
|
|
|
// Check to make sure this module is in our list.
|
2019-10-30 15:26:19 -07:00
|
|
|
if (module_sp && module_list.GetIndexForModule(module_sp.get()) !=
|
|
|
|
|
LLDB_INVALID_INDEX32) {
|
2016-01-05 19:51:51 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.Clear(true);
|
|
|
|
|
if (module_sp->ResolveSymbolContextForAddress(
|
|
|
|
|
so_addr, eSymbolContextEverything, sc) &
|
|
|
|
|
eSymbolContextLineEntry) {
|
|
|
|
|
sc_list.AppendIfUnique(sc, /*merge_symbol_into_function=*/false);
|
|
|
|
|
++num_matches;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2016-01-05 19:51:51 +00:00
|
|
|
StreamString addr_strm;
|
2016-02-24 02:05:55 +00:00
|
|
|
so_addr.Dump(&addr_strm, nullptr,
|
2016-01-05 19:51:51 +00:00
|
|
|
Address::DumpStyleModuleWithFileAddress);
|
|
|
|
|
error_strm.Printf(
|
|
|
|
|
"Address 0x%" PRIx64 " resolves to %s, but there is"
|
|
|
|
|
" no source information available for this address.\n",
|
|
|
|
|
addr, addr_strm.GetData());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-01-05 19:51:51 +00:00
|
|
|
StreamString addr_strm;
|
|
|
|
|
so_addr.Dump(&addr_strm, nullptr,
|
|
|
|
|
Address::DumpStyleModuleWithFileAddress);
|
|
|
|
|
error_strm.Printf("Address 0x%" PRIx64
|
|
|
|
|
" resolves to %s, but it cannot"
|
|
|
|
|
" be found in any modules.\n",
|
|
|
|
|
addr, addr_strm.GetData());
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else
|
2016-01-05 19:51:51 +00:00
|
|
|
error_strm.Printf("Unable to resolve address 0x%" PRIx64 ".\n", addr);
|
|
|
|
|
}
|
|
|
|
|
return num_matches;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// Dump the line entries found in functions matching the name specified in
|
|
|
|
|
// the option.
|
2016-01-05 19:51:51 +00:00
|
|
|
bool DumpLinesInFunctions(CommandReturnObject &result) {
|
|
|
|
|
SymbolContextList sc_list_funcs;
|
|
|
|
|
ConstString name(m_options.symbol_name.c_str());
|
|
|
|
|
SymbolContextList sc_list_lines;
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
|
|
|
|
uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-08-05 09:27:19 -07:00
|
|
|
ModuleFunctionSearchOptions function_options;
|
|
|
|
|
function_options.include_symbols = false;
|
|
|
|
|
function_options.include_inlines = true;
|
|
|
|
|
|
2013-07-11 16:40:56 +00:00
|
|
|
// Note: module_list can't be const& because FindFunctionSymbols isn't
|
2016-09-06 20:57:50 +00:00
|
|
|
// const.
|
2016-01-05 19:51:51 +00:00
|
|
|
ModuleList module_list =
|
|
|
|
|
(m_module_list.GetSize() > 0) ? m_module_list : target->GetImages();
|
2021-08-05 09:27:19 -07:00
|
|
|
module_list.FindFunctions(name, eFunctionNameTypeAuto, function_options,
|
|
|
|
|
sc_list_funcs);
|
2019-10-17 19:56:40 +00:00
|
|
|
size_t num_matches = sc_list_funcs.GetSize();
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
if (!num_matches) {
|
2013-07-11 16:40:56 +00:00
|
|
|
// If we didn't find any functions with that name, try searching for
|
|
|
|
|
// symbols that line up exactly with function addresses.
|
2016-01-05 19:51:51 +00:00
|
|
|
SymbolContextList sc_list_symbols;
|
2019-10-30 15:26:19 -07:00
|
|
|
module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto,
|
|
|
|
|
sc_list_symbols);
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list_symbols) {
|
2016-01-05 19:51:51 +00:00
|
|
|
if (sc.symbol && sc.symbol->ValueIsAddress()) {
|
|
|
|
|
const Address &base_address = sc.symbol->GetAddressRef();
|
|
|
|
|
Function *function = base_address.CalculateSymbolContextFunction();
|
|
|
|
|
if (function) {
|
|
|
|
|
sc_list_funcs.Append(SymbolContext(function));
|
|
|
|
|
num_matches++;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (num_matches == 0) {
|
|
|
|
|
result.AppendErrorWithFormat("Could not find function named \'%s\'.\n",
|
|
|
|
|
m_options.symbol_name.c_str());
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list_funcs) {
|
2016-01-05 19:51:51 +00:00
|
|
|
bool context_found_for_symbol = false;
|
|
|
|
|
// Loop through all the ranges in the function.
|
|
|
|
|
AddressRange range;
|
|
|
|
|
for (uint32_t r = 0;
|
|
|
|
|
sc.GetAddressRange(eSymbolContextEverything, r,
|
|
|
|
|
/*use_inline_block_range=*/true, range);
|
2016-09-06 20:57:50 +00:00
|
|
|
++r) {
|
2016-01-05 19:51:51 +00:00
|
|
|
// Append the symbol contexts for each address in the range to
|
|
|
|
|
// sc_list_lines.
|
|
|
|
|
const Address &base_address = range.GetBaseAddress();
|
|
|
|
|
const addr_t size = range.GetByteSize();
|
|
|
|
|
lldb::addr_t start_addr = base_address.GetLoadAddress(target);
|
|
|
|
|
if (start_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
|
start_addr = base_address.GetFileAddress();
|
|
|
|
|
lldb::addr_t end_addr = start_addr + size;
|
|
|
|
|
for (lldb::addr_t addr = start_addr; addr < end_addr;
|
|
|
|
|
addr += addr_byte_size) {
|
|
|
|
|
StreamString error_strm;
|
|
|
|
|
if (!GetSymbolContextsForAddress(module_list, addr, sc_list_lines,
|
|
|
|
|
error_strm))
|
|
|
|
|
result.AppendWarningWithFormat("in symbol '%s': %s",
|
2013-05-17 00:56:10 +00:00
|
|
|
sc.GetFunctionName().AsCString(),
|
2012-12-07 00:19:47 +00:00
|
|
|
error_strm.GetData());
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2016-01-05 19:51:51 +00:00
|
|
|
context_found_for_symbol = true;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (!context_found_for_symbol)
|
|
|
|
|
result.AppendWarningWithFormat("Unable to find line information"
|
|
|
|
|
" for matching symbol '%s'.\n",
|
|
|
|
|
sc.GetFunctionName().AsCString());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (sc_list_lines.GetSize() == 0) {
|
2013-05-17 00:56:10 +00:00
|
|
|
result.AppendErrorWithFormat("No line information could be found"
|
2016-01-05 19:51:51 +00:00
|
|
|
" for any symbols matching '%s'.\n",
|
|
|
|
|
name.AsCString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
FileSpec file_spec;
|
|
|
|
|
if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list_lines,
|
|
|
|
|
module_list, file_spec)) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"Unable to dump line information for symbol '%s'.\n",
|
|
|
|
|
name.AsCString());
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Dump the line entries found for the address specified in the option.
|
|
|
|
|
bool DumpLinesForAddress(CommandReturnObject &result) {
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
|
|
|
|
SymbolContextList sc_list;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
StreamString error_strm;
|
2012-12-07 00:19:47 +00:00
|
|
|
if (!GetSymbolContextsForAddress(target->GetImages(), m_options.address,
|
2016-01-05 19:51:51 +00:00
|
|
|
sc_list, error_strm)) {
|
2013-05-17 00:56:10 +00:00
|
|
|
result.AppendErrorWithFormat("%s.\n", error_strm.GetData());
|
2016-01-05 19:51:51 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
ModuleList module_list;
|
|
|
|
|
FileSpec file_spec;
|
|
|
|
|
if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
|
|
|
|
|
module_list, file_spec)) {
|
2012-12-07 00:19:47 +00:00
|
|
|
result.AppendErrorWithFormat("No modules contain load address 0x%" PRIx64
|
2016-09-06 20:57:50 +00:00
|
|
|
".\n",
|
2012-12-07 00:19:47 +00:00
|
|
|
m_options.address);
|
2016-01-05 19:51:51 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Dump the line entries found in the file specified in the option.
|
|
|
|
|
bool DumpLinesForFile(CommandReturnObject &result) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec file_spec(m_options.file_name);
|
2016-01-05 19:51:51 +00:00
|
|
|
const char *filename = m_options.file_name.c_str();
|
|
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
|
|
|
|
const ModuleList &module_list =
|
|
|
|
|
(m_module_list.GetSize() > 0) ? m_module_list : target->GetImages();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
bool displayed_something = false;
|
|
|
|
|
const size_t num_modules = module_list.GetSize();
|
|
|
|
|
for (uint32_t i = 0; i < num_modules; ++i) {
|
|
|
|
|
// Dump lines for this module.
|
|
|
|
|
Module *module = module_list.GetModulePointerAtIndex(i);
|
|
|
|
|
assert(module);
|
|
|
|
|
if (DumpFileLinesInModule(result.GetOutputStream(), module, file_spec))
|
|
|
|
|
displayed_something = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (!displayed_something) {
|
|
|
|
|
result.AppendErrorWithFormat("No source filenames matched '%s'.\n",
|
|
|
|
|
filename);
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Dump the line entries for the current frame.
|
|
|
|
|
bool DumpLinesForFrame(CommandReturnObject &result) {
|
|
|
|
|
StackFrame *cur_frame = m_exe_ctx.GetFramePtr();
|
2016-02-24 02:05:55 +00:00
|
|
|
if (cur_frame == nullptr) {
|
2016-01-05 19:51:51 +00:00
|
|
|
result.AppendError(
|
|
|
|
|
"No selected frame to use to find the default source.");
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!cur_frame->HasDebugInformation()) {
|
|
|
|
|
result.AppendError("No debug info for the selected frame.");
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2016-01-05 19:51:51 +00:00
|
|
|
const SymbolContext &sc =
|
|
|
|
|
cur_frame->GetSymbolContext(eSymbolContextLineEntry);
|
|
|
|
|
SymbolContextList sc_list;
|
|
|
|
|
sc_list.Append(sc);
|
|
|
|
|
ModuleList module_list;
|
|
|
|
|
FileSpec file_spec;
|
|
|
|
|
if (!DumpLinesInSymbolContexts(result.GetOutputStream(), sc_list,
|
|
|
|
|
module_list, file_spec)) {
|
|
|
|
|
result.AppendError(
|
|
|
|
|
"No source line info available for the selected frame.");
|
|
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
|
2023-10-30 10:21:00 -10:00
|
|
|
void DoExecute(Args &command, CommandReturnObject &result) override {
|
2016-01-05 19:51:51 +00:00
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-02-24 02:05:55 +00:00
|
|
|
if (target == nullptr) {
|
2019-04-27 06:19:42 +00:00
|
|
|
target = GetDebugger().GetSelectedTarget().get();
|
2016-01-05 19:51:51 +00:00
|
|
|
if (target == nullptr) {
|
|
|
|
|
result.AppendError("invalid target, create a debug target using the "
|
|
|
|
|
"'target create' command.");
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-01-05 19:51:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
|
|
|
|
|
result.GetOutputStream().SetAddressByteSize(addr_byte_size);
|
|
|
|
|
result.GetErrorStream().SetAddressByteSize(addr_byte_size);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-05 19:51:51 +00:00
|
|
|
// Collect the list of modules to search.
|
|
|
|
|
m_module_list.Clear();
|
2016-02-24 02:05:55 +00:00
|
|
|
if (!m_options.modules.empty()) {
|
2016-01-05 19:51:51 +00:00
|
|
|
for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec module_file_spec(m_options.modules[i]);
|
2016-01-05 19:51:51 +00:00
|
|
|
if (module_file_spec) {
|
|
|
|
|
ModuleSpec module_spec(module_file_spec);
|
2019-10-17 19:56:40 +00:00
|
|
|
target->GetImages().FindModules(module_spec, m_module_list);
|
|
|
|
|
if (m_module_list.IsEmpty())
|
2016-01-05 19:51:51 +00:00
|
|
|
result.AppendWarningWithFormat("No module found for '%s'.\n",
|
|
|
|
|
m_options.modules[i].c_str());
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
if (!m_module_list.GetSize()) {
|
|
|
|
|
result.AppendError("No modules match the input.");
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
} else if (target->GetImages().GetSize() == 0) {
|
|
|
|
|
result.AppendError("The target has no associated executable images.");
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2016-01-05 19:51:51 +00:00
|
|
|
|
|
|
|
|
// Check the arguments to see what lines we should dump.
|
|
|
|
|
if (!m_options.symbol_name.empty()) {
|
|
|
|
|
// Print lines for symbol.
|
|
|
|
|
if (DumpLinesInFunctions(result))
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
} else if (m_options.address != LLDB_INVALID_ADDRESS) {
|
|
|
|
|
// Print lines for an address.
|
|
|
|
|
if (DumpLinesForAddress(result))
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
} else if (!m_options.file_name.empty()) {
|
|
|
|
|
// Dump lines for a file.
|
|
|
|
|
if (DumpLinesForFile(result))
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
} else {
|
|
|
|
|
// Dump the line for the current frame.
|
|
|
|
|
if (DumpLinesForFrame(result))
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-06-08 21:56:10 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
CommandOptions m_options;
|
2016-01-05 19:51:51 +00:00
|
|
|
ModuleList m_module_list;
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#pragma mark CommandObjectSourceList
|
|
|
|
|
// CommandObjectSourceList
|
2019-07-23 11:08:12 +00:00
|
|
|
#define LLDB_OPTIONS_source_list
|
|
|
|
|
#include "CommandOptions.inc"
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
class CommandObjectSourceList : public CommandObjectParsed {
|
2010-07-07 03:36:20 +00:00
|
|
|
class CommandOptions : public Options {
|
|
|
|
|
public:
|
2022-03-31 13:20:46 -07:00
|
|
|
CommandOptions() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
~CommandOptions() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
|
Status error;
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
const int short_option = GetDefinitions()[option_idx].short_option;
|
2010-07-07 03:36:20 +00:00
|
|
|
switch (short_option) {
|
|
|
|
|
case 'l':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (option_arg.getAsInteger(0, start_line))
|
2011-10-26 00:56:27 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid line number: '%s'",
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2010-08-20 01:17:07 +00:00
|
|
|
case 'c':
|
2016-11-12 16:56:47 +00:00
|
|
|
if (option_arg.getAsInteger(0, num_lines))
|
2011-10-26 00:56:27 +00:00
|
|
|
error.SetErrorStringWithFormat("invalid line count: '%s'",
|
2016-11-12 16:56:47 +00:00
|
|
|
option_arg.str().c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
case 'f':
|
2020-01-28 20:23:46 +01:00
|
|
|
file_name = std::string(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2010-08-20 01:17:07 +00:00
|
|
|
case 'n':
|
2020-01-28 20:23:46 +01:00
|
|
|
symbol_name = std::string(option_arg);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
case 'a': {
|
2018-04-10 09:03:59 +00:00
|
|
|
address = OptionArgParser::ToAddress(execution_context, option_arg,
|
|
|
|
|
LLDB_INVALID_ADDRESS, &error);
|
2016-09-06 20:57:50 +00:00
|
|
|
} break;
|
2010-08-20 01:17:07 +00:00
|
|
|
case 's':
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
modules.push_back(std::string(option_arg));
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
case 'b':
|
|
|
|
|
show_bp_locs = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2013-01-09 03:27:33 +00:00
|
|
|
case 'r':
|
|
|
|
|
reverse = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2020-07-16 11:34:50 -07:00
|
|
|
case 'y':
|
|
|
|
|
{
|
|
|
|
|
OptionValueFileColonLine value;
|
|
|
|
|
Status fcl_err = value.SetValueFromString(option_arg);
|
|
|
|
|
if (!fcl_err.Success()) {
|
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
|
"Invalid value for file:line specifier: %s",
|
|
|
|
|
fcl_err.AsCString());
|
|
|
|
|
} else {
|
|
|
|
|
file_name = value.GetFileSpec().GetPath();
|
|
|
|
|
start_line = value.GetLineNumber();
|
|
|
|
|
// I don't see anything useful to do with a column number, but I don't
|
|
|
|
|
// want to complain since someone may well have cut and pasted a
|
|
|
|
|
// listing from somewhere that included a column.
|
|
|
|
|
}
|
|
|
|
|
} break;
|
2016-09-06 20:57:50 +00:00
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
return error;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2016-08-11 23:51:28 +00:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
2012-12-04 00:32:51 +00:00
|
|
|
file_spec.Clear();
|
2015-01-15 20:08:35 +00:00
|
|
|
file_name.clear();
|
|
|
|
|
symbol_name.clear();
|
2011-10-26 00:56:27 +00:00
|
|
|
address = LLDB_INVALID_ADDRESS;
|
2015-01-15 20:08:35 +00:00
|
|
|
start_line = 0;
|
2016-08-11 23:51:28 +00:00
|
|
|
num_lines = 0;
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
show_bp_locs = false;
|
2013-01-09 03:27:33 +00:00
|
|
|
reverse = false;
|
|
|
|
|
modules.clear();
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
2023-01-09 18:11:07 +01:00
|
|
|
return llvm::ArrayRef(g_source_list_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-22 20:22:55 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2011-03-24 21:19:54 +00:00
|
|
|
// Instance variables to hold the values for command options.
|
|
|
|
|
FileSpec file_spec;
|
2015-10-07 16:56:17 +00:00
|
|
|
std::string file_name;
|
2010-08-20 01:17:07 +00:00
|
|
|
std::string symbol_name;
|
2010-07-07 03:36:20 +00:00
|
|
|
lldb::addr_t address;
|
|
|
|
|
uint32_t start_line;
|
|
|
|
|
uint32_t num_lines;
|
2019-11-06 14:44:39 -08:00
|
|
|
std::vector<std::string> modules;
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
bool show_bp_locs;
|
2010-07-07 03:36:20 +00:00
|
|
|
bool reverse;
|
|
|
|
|
};
|
2016-02-24 02:05:55 +00:00
|
|
|
|
2011-03-24 21:19:54 +00:00
|
|
|
public:
|
|
|
|
|
CommandObjectSourceList(CommandInterpreter &interpreter)
|
2016-07-14 22:03:10 +00:00
|
|
|
: CommandObjectParsed(interpreter, "source list",
|
2011-03-24 21:19:54 +00:00
|
|
|
"Display source code for the current target "
|
|
|
|
|
"process as specified by options.",
|
2022-01-23 11:07:14 -08:00
|
|
|
nullptr, eCommandRequiresTarget) {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-03-24 21:19:54 +00:00
|
|
|
~CommandObjectSourceList() override = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-03-24 21:19:54 +00:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2023-01-07 14:18:35 -08:00
|
|
|
std::optional<std::string> GetRepeatCommand(Args ¤t_command_args,
|
|
|
|
|
uint32_t index) override {
|
2018-04-30 16:49:04 +00:00
|
|
|
// This is kind of gross, but the command hasn't been parsed yet so we
|
|
|
|
|
// can't look at the option values for this invocation... I have to scan
|
|
|
|
|
// the arguments directly.
|
2016-12-09 05:46:41 +00:00
|
|
|
auto iter =
|
|
|
|
|
llvm::find_if(current_command_args, [](const Args::ArgEntry &e) {
|
2019-09-13 11:26:48 +00:00
|
|
|
return e.ref() == "-r" || e.ref() == "--reverse";
|
2016-12-09 05:46:41 +00:00
|
|
|
});
|
|
|
|
|
if (iter == current_command_args.end())
|
2022-02-04 15:16:31 -08:00
|
|
|
return m_cmd_name;
|
2016-12-09 05:46:41 +00:00
|
|
|
|
|
|
|
|
if (m_reverse_name.empty()) {
|
|
|
|
|
m_reverse_name = m_cmd_name;
|
|
|
|
|
m_reverse_name.append(" -r");
|
|
|
|
|
}
|
2022-02-04 15:16:31 -08:00
|
|
|
return m_reverse_name;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
protected:
|
2010-07-07 03:36:20 +00:00
|
|
|
struct SourceInfo {
|
|
|
|
|
ConstString function;
|
|
|
|
|
LineEntry line_entry;
|
2016-07-14 22:03:10 +00:00
|
|
|
|
2019-03-06 21:22:25 +00:00
|
|
|
SourceInfo(ConstString name, const LineEntry &line_entry)
|
2016-07-14 22:03:10 +00:00
|
|
|
: function(name), line_entry(line_entry) {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-03-31 13:20:46 -07:00
|
|
|
SourceInfo() = default;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
bool IsValid() const { return (bool)function && line_entry.IsValid(); }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
bool operator==(const SourceInfo &rhs) const {
|
|
|
|
|
return function == rhs.function &&
|
2024-01-16 21:09:23 -08:00
|
|
|
*line_entry.original_file_sp == *rhs.line_entry.original_file_sp &&
|
2016-07-14 22:03:10 +00:00
|
|
|
line_entry.line == rhs.line_entry.line;
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 02:05:55 +00:00
|
|
|
bool operator!=(const SourceInfo &rhs) const {
|
|
|
|
|
return function != rhs.function ||
|
2024-01-16 21:09:23 -08:00
|
|
|
*line_entry.original_file_sp != *rhs.line_entry.original_file_sp ||
|
2016-02-24 02:05:55 +00:00
|
|
|
line_entry.line != rhs.line_entry.line;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
bool operator<(const SourceInfo &rhs) const {
|
|
|
|
|
if (function.GetCString() < rhs.function.GetCString())
|
2013-05-17 00:56:10 +00:00
|
|
|
return true;
|
2024-03-21 08:40:08 -07:00
|
|
|
if (line_entry.GetFile().GetDirectory().GetCString() <
|
|
|
|
|
rhs.line_entry.GetFile().GetDirectory().GetCString())
|
2013-05-17 00:56:10 +00:00
|
|
|
return true;
|
2024-03-21 08:40:08 -07:00
|
|
|
if (line_entry.GetFile().GetFilename().GetCString() <
|
|
|
|
|
rhs.line_entry.GetFile().GetFilename().GetCString())
|
2013-05-17 00:56:10 +00:00
|
|
|
return true;
|
2015-10-07 16:56:17 +00:00
|
|
|
if (line_entry.line < rhs.line_entry.line)
|
2010-07-07 03:36:20 +00:00
|
|
|
return true;
|
2013-05-17 00:56:10 +00:00
|
|
|
return false;
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
};
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2015-10-07 16:56:17 +00:00
|
|
|
size_t DisplayFunctionSource(const SymbolContext &sc, SourceInfo &source_info,
|
|
|
|
|
CommandReturnObject &result) {
|
2013-01-09 03:27:33 +00:00
|
|
|
if (!source_info.IsValid()) {
|
|
|
|
|
source_info.function = sc.GetFunctionName();
|
|
|
|
|
source_info.line_entry = sc.GetFunctionStartLineEntry();
|
2012-06-08 21:56:10 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2012-06-08 21:56:10 +00:00
|
|
|
if (sc.function) {
|
2013-05-17 00:56:10 +00:00
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
FileSpec start_file;
|
|
|
|
|
uint32_t start_line;
|
|
|
|
|
uint32_t end_line;
|
|
|
|
|
FileSpec end_file;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
if (sc.block == nullptr) {
|
|
|
|
|
// Not an inlined function
|
|
|
|
|
sc.function->GetStartLineSourceInfo(start_file, start_line);
|
|
|
|
|
if (start_line == 0) {
|
|
|
|
|
result.AppendErrorWithFormat("Could not find line information for "
|
|
|
|
|
"start of function: \"%s\".\n",
|
|
|
|
|
source_info.function.GetCString());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
sc.function->GetEndLineSourceInfo(end_file, end_line);
|
|
|
|
|
} else {
|
|
|
|
|
// We have an inlined function
|
2024-03-21 08:40:08 -07:00
|
|
|
start_file = source_info.line_entry.GetFile();
|
2013-05-17 00:56:10 +00:00
|
|
|
start_line = source_info.line_entry.line;
|
|
|
|
|
end_line = start_line + m_options.num_lines;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
// This is a little hacky, but the first line table entry for a function
|
2018-04-30 16:49:04 +00:00
|
|
|
// points to the "{" that starts the function block. It would be nice to
|
|
|
|
|
// actually get the function declaration in there too. So back up a bit,
|
|
|
|
|
// but not further than what you're going to display.
|
2013-05-17 00:56:10 +00:00
|
|
|
uint32_t extra_lines;
|
|
|
|
|
if (m_options.num_lines >= 10)
|
|
|
|
|
extra_lines = 5;
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2013-05-17 00:56:10 +00:00
|
|
|
extra_lines = m_options.num_lines / 2;
|
|
|
|
|
uint32_t line_no;
|
|
|
|
|
if (start_line <= extra_lines)
|
|
|
|
|
line_no = 1;
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2013-05-17 00:56:10 +00:00
|
|
|
line_no = start_line - extra_lines;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
// For fun, if the function is shorter than the number of lines we're
|
2018-04-30 16:49:04 +00:00
|
|
|
// supposed to display, only display the function...
|
2016-05-11 22:46:53 +00:00
|
|
|
if (end_line != 0) {
|
|
|
|
|
if (m_options.num_lines > end_line - line_no)
|
2013-05-17 00:56:10 +00:00
|
|
|
m_options.num_lines = end_line - line_no + extra_lines;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
m_breakpoint_locations.Clear();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
if (m_options.show_bp_locs) {
|
|
|
|
|
const bool show_inlines = true;
|
|
|
|
|
m_breakpoint_locations.Reset(start_file, 0, show_inlines);
|
|
|
|
|
SearchFilterForUnconstrainedSearches target_search_filter(
|
|
|
|
|
m_exe_ctx.GetTargetSP());
|
|
|
|
|
target_search_filter.Search(m_breakpoint_locations);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
result.AppendMessageWithFormat("File: %s\n",
|
|
|
|
|
start_file.GetPath().c_str());
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
// We don't care about the column here.
|
|
|
|
|
const uint32_t column = 0;
|
2013-05-17 00:56:10 +00:00
|
|
|
return target->GetSourceManager().DisplaySourceLinesWithLineNumbers(
|
2017-11-17 01:19:59 +00:00
|
|
|
start_file, line_no, column, 0, m_options.num_lines, "",
|
2016-01-05 19:51:51 +00:00
|
|
|
&result.GetOutputStream(), GetBreakpointLocations());
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2013-05-17 00:56:10 +00:00
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"Could not find function info for: \"%s\".\n",
|
|
|
|
|
m_options.symbol_name.c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-05-17 00:56:10 +00:00
|
|
|
return 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// From Jim: The FindMatchingFunctions / FindMatchingFunctionSymbols
|
|
|
|
|
// functions "take a possibly empty vector of strings which are names of
|
|
|
|
|
// modules, and run the two search functions on the subset of the full module
|
|
|
|
|
// list that matches the strings in the input vector". If we wanted to put
|
|
|
|
|
// these somewhere, there should probably be a module-filter-list that can be
|
|
|
|
|
// passed to the various ModuleList::Find* calls, which would either be a
|
|
|
|
|
// vector of string names or a ModuleSpecList.
|
2019-10-17 19:56:40 +00:00
|
|
|
void FindMatchingFunctions(Target *target, ConstString name,
|
2019-10-30 15:26:19 -07:00
|
|
|
SymbolContextList &sc_list) {
|
2013-07-11 16:40:56 +00:00
|
|
|
// Displaying the source for a symbol:
|
2013-05-17 00:56:10 +00:00
|
|
|
if (m_options.num_lines == 0)
|
2013-07-11 16:40:56 +00:00
|
|
|
m_options.num_lines = 10;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2021-08-05 09:27:19 -07:00
|
|
|
ModuleFunctionSearchOptions function_options;
|
|
|
|
|
function_options.include_symbols = true;
|
|
|
|
|
function_options.include_inlines = false;
|
|
|
|
|
|
2013-05-17 00:56:10 +00:00
|
|
|
const size_t num_modules = m_options.modules.size();
|
2013-07-11 16:40:56 +00:00
|
|
|
if (num_modules > 0) {
|
|
|
|
|
ModuleList matching_modules;
|
2013-05-17 00:56:10 +00:00
|
|
|
for (size_t i = 0; i < num_modules; ++i) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec module_file_spec(m_options.modules[i]);
|
2013-05-17 00:56:10 +00:00
|
|
|
if (module_file_spec) {
|
|
|
|
|
ModuleSpec module_spec(module_file_spec);
|
|
|
|
|
matching_modules.Clear();
|
|
|
|
|
target->GetImages().FindModules(module_spec, matching_modules);
|
2021-08-05 09:27:19 -07:00
|
|
|
|
2019-10-30 15:26:19 -07:00
|
|
|
matching_modules.FindFunctions(name, eFunctionNameTypeAuto,
|
2021-08-05 09:27:19 -07:00
|
|
|
function_options, sc_list);
|
2013-05-17 00:56:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2019-10-17 19:56:40 +00:00
|
|
|
target->GetImages().FindFunctions(name, eFunctionNameTypeAuto,
|
2021-08-05 09:27:19 -07:00
|
|
|
function_options, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 19:56:40 +00:00
|
|
|
void FindMatchingFunctionSymbols(Target *target, ConstString name,
|
|
|
|
|
SymbolContextList &sc_list) {
|
2013-05-17 00:56:10 +00:00
|
|
|
const size_t num_modules = m_options.modules.size();
|
|
|
|
|
if (num_modules > 0) {
|
|
|
|
|
ModuleList matching_modules;
|
|
|
|
|
for (size_t i = 0; i < num_modules; ++i) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec module_file_spec(m_options.modules[i]);
|
2013-05-17 00:56:10 +00:00
|
|
|
if (module_file_spec) {
|
2013-07-11 16:40:56 +00:00
|
|
|
ModuleSpec module_spec(module_file_spec);
|
|
|
|
|
matching_modules.Clear();
|
2013-05-17 00:56:10 +00:00
|
|
|
target->GetImages().FindModules(module_spec, matching_modules);
|
2019-10-17 19:56:40 +00:00
|
|
|
matching_modules.FindFunctionSymbols(name, eFunctionNameTypeAuto,
|
|
|
|
|
sc_list);
|
2013-05-17 00:56:10 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-05-17 00:56:10 +00:00
|
|
|
} else {
|
2019-10-17 19:56:40 +00:00
|
|
|
target->GetImages().FindFunctionSymbols(name, eFunctionNameTypeAuto,
|
|
|
|
|
sc_list);
|
2013-05-17 00:56:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 10:21:00 -10:00
|
|
|
void DoExecute(Args &command, CommandReturnObject &result) override {
|
2014-12-06 01:28:03 +00:00
|
|
|
Target *target = m_exe_ctx.GetTargetPtr();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-12-06 01:28:03 +00:00
|
|
|
if (!m_options.symbol_name.empty()) {
|
|
|
|
|
SymbolContextList sc_list;
|
|
|
|
|
ConstString name(m_options.symbol_name.c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-12-06 01:28:03 +00:00
|
|
|
// Displaying the source for a symbol. Search for function named name.
|
2019-10-17 19:56:40 +00:00
|
|
|
FindMatchingFunctions(target, name, sc_list);
|
2023-05-04 18:19:15 -07:00
|
|
|
if (sc_list.GetSize() == 0) {
|
2013-05-17 00:56:10 +00:00
|
|
|
// If we didn't find any functions with that name, try searching for
|
2018-04-30 16:49:04 +00:00
|
|
|
// symbols that line up exactly with function addresses.
|
2013-05-17 00:56:10 +00:00
|
|
|
SymbolContextList sc_list_symbols;
|
2019-10-17 19:56:40 +00:00
|
|
|
FindMatchingFunctionSymbols(target, name, sc_list_symbols);
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list_symbols) {
|
2013-05-17 00:56:10 +00:00
|
|
|
if (sc.symbol && sc.symbol->ValueIsAddress()) {
|
2015-06-25 21:46:34 +00:00
|
|
|
const Address &base_address = sc.symbol->GetAddressRef();
|
2013-05-17 00:56:10 +00:00
|
|
|
Function *function = base_address.CalculateSymbolContextFunction();
|
2013-07-11 16:40:56 +00:00
|
|
|
if (function) {
|
|
|
|
|
sc_list.Append(SymbolContext(function));
|
2013-05-17 00:56:10 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:19:15 -07:00
|
|
|
if (sc_list.GetSize() == 0) {
|
2013-07-11 16:40:56 +00:00
|
|
|
result.AppendErrorWithFormat("Could not find function named: \"%s\".\n",
|
|
|
|
|
m_options.symbol_name.c_str());
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:19:15 -07:00
|
|
|
std::set<SourceInfo> source_match_set;
|
|
|
|
|
bool displayed_something = false;
|
|
|
|
|
for (const SymbolContext &sc : sc_list) {
|
|
|
|
|
SourceInfo source_info(sc.GetFunctionName(),
|
|
|
|
|
sc.GetFunctionStartLineEntry());
|
|
|
|
|
if (source_info.IsValid() &&
|
|
|
|
|
source_match_set.find(source_info) == source_match_set.end()) {
|
|
|
|
|
source_match_set.insert(source_info);
|
|
|
|
|
if (DisplayFunctionSource(sc, source_info, result))
|
|
|
|
|
displayed_something = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-04 18:19:15 -07:00
|
|
|
if (displayed_something)
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
else
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2013-07-11 16:40:56 +00:00
|
|
|
} else if (m_options.address != LLDB_INVALID_ADDRESS) {
|
2012-12-07 00:19:47 +00:00
|
|
|
Address so_addr;
|
2013-07-11 16:40:56 +00:00
|
|
|
StreamString error_strm;
|
|
|
|
|
SymbolContextList sc_list;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-07-11 16:40:56 +00:00
|
|
|
if (target->GetSectionLoadList().IsEmpty()) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// The target isn't loaded yet, we need to lookup the file address in
|
|
|
|
|
// all modules
|
2013-07-11 16:40:56 +00:00
|
|
|
const ModuleList &module_list = target->GetImages();
|
|
|
|
|
const size_t num_modules = module_list.GetSize();
|
|
|
|
|
for (size_t i = 0; i < num_modules; ++i) {
|
2016-01-05 19:51:51 +00:00
|
|
|
ModuleSP module_sp(module_list.GetModuleAtIndex(i));
|
2012-12-07 00:19:47 +00:00
|
|
|
if (module_sp &&
|
2013-07-11 16:40:56 +00:00
|
|
|
module_sp->ResolveFileAddress(m_options.address, so_addr)) {
|
|
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.Clear(true);
|
2012-12-07 00:19:47 +00:00
|
|
|
if (module_sp->ResolveSymbolContextForAddress(
|
|
|
|
|
so_addr, eSymbolContextEverything, sc) &
|
|
|
|
|
eSymbolContextLineEntry)
|
2013-07-11 16:40:56 +00:00
|
|
|
sc_list.Append(sc);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2013-07-11 16:40:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sc_list.GetSize() == 0) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"no modules have source information for file address 0x%" PRIx64
|
|
|
|
|
".\n",
|
|
|
|
|
m_options.address);
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2013-07-11 16:40:56 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2018-04-30 16:49:04 +00:00
|
|
|
// The target has some things loaded, resolve this address to a compile
|
|
|
|
|
// unit + file + line and display
|
2013-07-11 16:40:56 +00:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress(m_options.address,
|
2012-12-07 00:19:47 +00:00
|
|
|
so_addr)) {
|
|
|
|
|
ModuleSP module_sp(so_addr.GetModule());
|
|
|
|
|
if (module_sp) {
|
2013-07-11 16:40:56 +00:00
|
|
|
SymbolContext sc;
|
|
|
|
|
sc.Clear(true);
|
2012-12-07 00:19:47 +00:00
|
|
|
if (module_sp->ResolveSymbolContextForAddress(
|
2013-07-11 16:40:56 +00:00
|
|
|
so_addr, eSymbolContextEverything, sc) &
|
2012-12-07 00:19:47 +00:00
|
|
|
eSymbolContextLineEntry) {
|
2013-07-11 16:40:56 +00:00
|
|
|
sc_list.Append(sc);
|
|
|
|
|
} else {
|
|
|
|
|
so_addr.Dump(&error_strm, nullptr,
|
|
|
|
|
Address::DumpStyleModuleWithFileAddress);
|
|
|
|
|
result.AppendErrorWithFormat("address resolves to %s, but there "
|
|
|
|
|
"is no line table information "
|
2012-12-07 00:19:47 +00:00
|
|
|
"available for this address.\n",
|
|
|
|
|
error_strm.GetData());
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-11 16:40:56 +00:00
|
|
|
}
|
2010-07-07 03:36:20 +00:00
|
|
|
|
|
|
|
|
if (sc_list.GetSize() == 0) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"no modules contain load address 0x%" PRIx64 ".\n",
|
|
|
|
|
m_options.address);
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list) {
|
2012-12-07 00:19:47 +00:00
|
|
|
if (sc.comp_unit) {
|
|
|
|
|
if (m_options.show_bp_locs) {
|
|
|
|
|
m_breakpoint_locations.Clear();
|
|
|
|
|
const bool show_inlines = true;
|
2019-11-28 16:22:44 +01:00
|
|
|
m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0,
|
|
|
|
|
show_inlines);
|
2014-12-06 01:28:03 +00:00
|
|
|
SearchFilterForUnconstrainedSearches target_search_filter(
|
|
|
|
|
target->shared_from_this());
|
2012-12-07 00:19:47 +00:00
|
|
|
target_search_filter.Search(m_breakpoint_locations);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-07 00:19:47 +00:00
|
|
|
bool show_fullpaths = true;
|
|
|
|
|
bool show_module = true;
|
|
|
|
|
bool show_inlined_frames = true;
|
2014-10-10 23:07:36 +00:00
|
|
|
const bool show_function_arguments = true;
|
2015-02-13 23:24:21 +00:00
|
|
|
const bool show_function_name = true;
|
2012-12-07 00:19:47 +00:00
|
|
|
sc.DumpStopContext(&result.GetOutputStream(),
|
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-09 19:44:40 +00:00
|
|
|
m_exe_ctx.GetBestExecutionContextScope(),
|
2012-12-07 00:19:47 +00:00
|
|
|
sc.line_entry.range.GetBaseAddress(),
|
2016-08-26 23:28:47 +00:00
|
|
|
show_fullpaths, show_module, show_inlined_frames,
|
2014-10-10 23:07:36 +00:00
|
|
|
show_function_arguments, show_function_name);
|
2012-12-07 00:19:47 +00:00
|
|
|
result.GetOutputStream().EOL();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-03-13 18:25:49 +00:00
|
|
|
if (m_options.num_lines == 0)
|
|
|
|
|
m_options.num_lines = 10;
|
2010-07-07 03:36:20 +00:00
|
|
|
|
2013-07-11 16:40:56 +00:00
|
|
|
size_t lines_to_back_up =
|
2010-08-20 01:17:07 +00:00
|
|
|
m_options.num_lines >= 10 ? 5 : m_options.num_lines / 2;
|
2013-07-11 16:40:56 +00:00
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
const uint32_t column =
|
2019-04-27 06:19:42 +00:00
|
|
|
(GetDebugger().GetStopShowColumn() != eStopShowColumnNone)
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
? sc.line_entry.column
|
|
|
|
|
: 0;
|
2013-05-17 00:56:10 +00:00
|
|
|
target->GetSourceManager().DisplaySourceLinesWithLineNumbers(
|
2019-11-28 16:22:44 +01:00
|
|
|
sc.comp_unit->GetPrimaryFile(), sc.line_entry.line, column,
|
|
|
|
|
lines_to_back_up, m_options.num_lines - lines_to_back_up, "->",
|
2013-05-17 00:56:10 +00:00
|
|
|
&result.GetOutputStream(), GetBreakpointLocations());
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2010-08-20 01:17:07 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-12-07 00:19:47 +00:00
|
|
|
} else if (m_options.file_name.empty()) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// Last valid source manager context, or the current frame if no valid
|
|
|
|
|
// last context in source manager. One little trick here, if you type the
|
|
|
|
|
// exact same list command twice in a row, it is more likely because you
|
|
|
|
|
// typed it once, then typed it again
|
2012-12-07 00:19:47 +00:00
|
|
|
if (m_options.start_line == 0) {
|
2014-12-06 01:28:03 +00:00
|
|
|
if (target->GetSourceManager().DisplayMoreWithLineNumbers(
|
2012-12-07 00:19:47 +00:00
|
|
|
&result.GetOutputStream(), m_options.num_lines,
|
|
|
|
|
m_options.reverse, GetBreakpointLocations())) {
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
}
|
2010-08-20 01:17:07 +00:00
|
|
|
} else {
|
2010-07-07 03:36:20 +00:00
|
|
|
if (m_options.num_lines == 0)
|
2011-09-29 20:22:33 +00:00
|
|
|
m_options.num_lines = 10;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-09-29 20:22:33 +00:00
|
|
|
if (m_options.show_bp_locs) {
|
|
|
|
|
SourceManager::FileSP last_file_sp(
|
|
|
|
|
target->GetSourceManager().GetLastFile());
|
2013-03-13 18:25:49 +00:00
|
|
|
if (last_file_sp) {
|
|
|
|
|
const bool show_inlines = true;
|
2011-09-08 22:13:49 +00:00
|
|
|
m_breakpoint_locations.Reset(last_file_sp->GetFileSpec(), 0,
|
2011-04-20 18:52:45 +00:00
|
|
|
show_inlines);
|
2014-12-06 01:28:03 +00:00
|
|
|
SearchFilterForUnconstrainedSearches target_search_filter(
|
|
|
|
|
target->shared_from_this());
|
2011-04-20 18:52:45 +00:00
|
|
|
target_search_filter.Search(m_breakpoint_locations);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
m_breakpoint_locations.Clear();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
const uint32_t column = 0;
|
2011-09-08 22:13:49 +00:00
|
|
|
if (target->GetSourceManager()
|
|
|
|
|
.DisplaySourceLinesWithLineNumbersUsingLastFile(
|
2010-07-07 03:36:20 +00:00
|
|
|
m_options.start_line, // Line to display
|
2013-03-13 18:25:49 +00:00
|
|
|
m_options.num_lines, // Lines after line to
|
|
|
|
|
UINT32_MAX, // Don't mark "line"
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
column,
|
|
|
|
|
"", // Don't mark "line"
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
&result.GetOutputStream(), GetBreakpointLocations())) {
|
2010-07-07 03:36:20 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
} else {
|
2010-07-07 03:36:20 +00:00
|
|
|
const char *filename = m_options.file_name.c_str();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
bool check_inlines = false;
|
|
|
|
|
SymbolContextList sc_list;
|
2010-08-20 01:17:07 +00:00
|
|
|
size_t num_matches = 0;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-02-24 02:05:55 +00:00
|
|
|
if (!m_options.modules.empty()) {
|
2010-08-20 01:17:07 +00:00
|
|
|
ModuleList matching_modules;
|
2013-01-25 18:06:21 +00:00
|
|
|
for (size_t i = 0, e = m_options.modules.size(); i < e; ++i) {
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSpec module_file_spec(m_options.modules[i]);
|
2012-02-26 05:51:37 +00:00
|
|
|
if (module_file_spec) {
|
|
|
|
|
ModuleSpec module_spec(module_file_spec);
|
2010-08-20 01:17:07 +00:00
|
|
|
matching_modules.Clear();
|
2012-02-26 05:51:37 +00:00
|
|
|
target->GetImages().FindModules(module_spec, matching_modules);
|
2010-08-20 01:17:07 +00:00
|
|
|
num_matches += matching_modules.ResolveSymbolContextForFilePath(
|
|
|
|
|
filename, 0, check_inlines,
|
2018-10-25 20:45:19 +00:00
|
|
|
SymbolContextItem(eSymbolContextModule |
|
|
|
|
|
eSymbolContextCompUnit),
|
|
|
|
|
sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-08-20 01:17:07 +00:00
|
|
|
num_matches = target->GetImages().ResolveSymbolContextForFilePath(
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
filename, 0, check_inlines,
|
|
|
|
|
eSymbolContextModule | eSymbolContextCompUnit, sc_list);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-20 01:17:07 +00:00
|
|
|
if (num_matches == 0) {
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
result.AppendErrorWithFormat("Could not find source file \"%s\".\n",
|
|
|
|
|
m_options.file_name.c_str());
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2010-08-20 01:17:07 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-08-20 01:17:07 +00:00
|
|
|
if (num_matches > 1) {
|
|
|
|
|
bool got_multiple = false;
|
2019-11-28 16:22:44 +01:00
|
|
|
CompileUnit *test_cu = nullptr;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2023-05-04 18:19:15 -07:00
|
|
|
for (const SymbolContext &sc : sc_list) {
|
2012-12-07 00:19:47 +00:00
|
|
|
if (sc.comp_unit) {
|
2019-11-28 16:22:44 +01:00
|
|
|
if (test_cu) {
|
|
|
|
|
if (test_cu != sc.comp_unit)
|
2010-08-20 01:17:07 +00:00
|
|
|
got_multiple = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2010-08-20 01:17:07 +00:00
|
|
|
} else
|
2019-11-28 16:22:44 +01:00
|
|
|
test_cu = sc.comp_unit;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-08-20 01:17:07 +00:00
|
|
|
}
|
|
|
|
|
if (got_multiple) {
|
|
|
|
|
result.AppendErrorWithFormat(
|
|
|
|
|
"Multiple source files found matching: \"%s.\"\n",
|
|
|
|
|
m_options.file_name.c_str());
|
2023-10-30 10:21:00 -10:00
|
|
|
return;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-11 16:40:56 +00:00
|
|
|
SymbolContext sc;
|
2010-08-20 01:17:07 +00:00
|
|
|
if (sc_list.GetContextAtIndex(0, sc)) {
|
2012-12-07 00:19:47 +00:00
|
|
|
if (sc.comp_unit) {
|
2011-09-08 22:13:49 +00:00
|
|
|
if (m_options.show_bp_locs) {
|
2012-12-07 00:19:47 +00:00
|
|
|
const bool show_inlines = true;
|
2019-11-28 16:22:44 +01:00
|
|
|
m_breakpoint_locations.Reset(sc.comp_unit->GetPrimaryFile(), 0,
|
|
|
|
|
show_inlines);
|
2014-12-06 01:28:03 +00:00
|
|
|
SearchFilterForUnconstrainedSearches target_search_filter(
|
|
|
|
|
target->shared_from_this());
|
2012-12-07 00:19:47 +00:00
|
|
|
target_search_filter.Search(m_breakpoint_locations);
|
2010-08-20 01:17:07 +00:00
|
|
|
} else
|
2012-12-07 00:19:47 +00:00
|
|
|
m_breakpoint_locations.Clear();
|
2014-08-18 14:48:24 +00:00
|
|
|
|
2010-08-20 01:17:07 +00:00
|
|
|
if (m_options.num_lines == 0)
|
2010-09-08 22:55:31 +00:00
|
|
|
m_options.num_lines = 10;
|
add stop column highlighting support
This change introduces optional marking of the column within a source
line where a thread is stopped. This marking will show up when the
source code for a thread stop is displayed, when the debug info
knows the column information, and if the optional column marking is
enabled.
There are two separate methods for handling the marking of the stop
column:
* via ANSI terminal codes, which are added inline to the source line
display. The default ANSI mark-up is to underline the column.
* via a pure text-based caret that is added in the appropriate column
in a newly-inserted blank line underneath the source line in
question.
There are some new options that control how this all works.
* settings set stop-show-column
This takes one of 4 values:
* ansi-or-caret: use the ANSI terminal code mechanism if LLDB
is running with color enabled; if not, use the caret-based,
pure text method (see the "caret" mode below).
* ansi: only use the ANSI terminal code mechanism to highlight
the stop line. If LLDB is running with color disabled, no
stop column marking will occur.
* caret: only use the pure text caret method, which introduces
a newly-inserted line underneath the current line, where
the only character in the new line is a caret that highlights
the stop column in question.
* none: no stop column marking will be attempted.
* settings set stop-show-column-ansi-prefix
This is a text format that indicates the ANSI formatting
code to insert into the stream immediately preceding the
column where the stop column character will be marked up.
It defaults to ${ansi.underline}; however, it can contain
any valid LLDB format codes, e.g.
${ansi.fg.red}${ansi.bold}${ansi.underline}
* settings set stop-show-column-ansi-suffix
This is the text format that specifies the ANSI terminal
codes to end the markup that was started with the prefix
described above. It defaults to: ${ansi.normal}. This
should be sufficient for the common cases.
Significant leg-work was done by Adrian Prantl. (Thanks, Adrian!)
differential review: https://reviews.llvm.org/D20835
reviewers: clayborg, jingham
llvm-svn: 282105
2016-09-21 20:13:14 +00:00
|
|
|
const uint32_t column = 0;
|
2014-08-18 14:48:24 +00:00
|
|
|
target->GetSourceManager().DisplaySourceLinesWithLineNumbers(
|
2019-11-28 16:22:44 +01:00
|
|
|
sc.comp_unit->GetPrimaryFile(), m_options.start_line, column, 0,
|
2019-10-30 15:26:19 -07:00
|
|
|
m_options.num_lines, "", &result.GetOutputStream(),
|
|
|
|
|
GetBreakpointLocations());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-12-06 01:28:03 +00:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
} else {
|
2011-09-08 22:13:49 +00:00
|
|
|
result.AppendErrorWithFormat("No comp unit found for: \"%s.\"\n",
|
2010-08-20 01:17:07 +00:00
|
|
|
m_options.file_name.c_str());
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
const SymbolContextList *GetBreakpointLocations() {
|
|
|
|
|
if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0)
|
|
|
|
|
return &m_breakpoint_locations.GetFileLineMatches();
|
2016-02-24 02:05:55 +00:00
|
|
|
return nullptr;
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
CommandOptions m_options;
|
Added a new option to the "source list" command that allows us to see where
line tables specify breakpoints can be set in the source. When dumping the
source, the number of breakpoints that can be set on a source line are shown
as a prefix:
(lldb) source list -f test.c -l1 -c222 -b
1 #include <stdio.h>
2 #include <sys/fcntl.h>
3 #include <unistd.h>
4 int
5 sleep_loop (const int num_secs)
[2] 6 {
7 int i;
[1] 8 for (i=0; i<num_secs; ++i)
9 {
[1] 10 printf("%d of %i - sleep(1);\n", i, num_secs);
[1] 11 sleep(1);
12 }
13 return 0;
[1] 14 }
15
16 int
17 main (int argc, char const* argv[])
[1] 18 {
[1] 19 printf("Process: %i\n\n", getpid());
[1] 20 puts("Press any key to continue..."); getchar();
[1] 21 sleep_loop (20);
22 return 12;
[1] 23 }
Above we can see there are two breakpoints for line 6 and one breakpoint for
lines 8, 10, 11, 14, 18, 19, 20, 21 and 23. All other lines have no line table
entries for them. This helps visualize the data provided in the debug
information without having to manually dump all line tables. It also includes
all inline breakpoint that may result for a given file which can also be very
handy to see.
llvm-svn: 129747
2011-04-19 04:19:37 +00:00
|
|
|
FileLineResolver m_breakpoint_locations;
|
2013-01-09 03:27:33 +00:00
|
|
|
std::string m_reverse_name;
|
2010-07-07 03:36:20 +00:00
|
|
|
};
|
|
|
|
|
|
2023-06-26 09:16:23 -07:00
|
|
|
class CommandObjectSourceCacheDump : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectSourceCacheDump(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(interpreter, "source cache dump",
|
|
|
|
|
"Dump the state of the source code cache. Intended "
|
|
|
|
|
"to be used for debugging LLDB itself.",
|
|
|
|
|
nullptr) {}
|
|
|
|
|
|
|
|
|
|
~CommandObjectSourceCacheDump() override = default;
|
|
|
|
|
|
|
|
|
|
protected:
|
2023-10-30 10:21:00 -10:00
|
|
|
void DoExecute(Args &command, CommandReturnObject &result) override {
|
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:
1. We always resolve the path.
2. We always check the timestamp.
3. We always recheck the file system for negative cache hits.
D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.
We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:
- The cache at the debugger level works the way it does today. There is
no negative cache: if we can't find the file on disk, we'll try again
next time the cache is queried. If a cached file's timestamp changes
or if its path remapping changes, the cached file is evicted and we
reload it from disk.
- The cache at the process level is design to avoid accessing the file
system. It doesn't check the file's modification time. It caches
negative results, so if a file didn't exist, it doesn't try to reread
it from disk. Checking if the path remapping changed is cheap
(doesn't involve checking the file system) and is the only way for a
file to get evicted from the process cache.
The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.
For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.
In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.
rdar://110787562
Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:06:57 -07:00
|
|
|
// Dump the debugger source cache.
|
|
|
|
|
result.GetOutputStream() << "Debugger Source File Cache\n";
|
2023-06-26 09:16:23 -07:00
|
|
|
SourceManager::SourceFileCache &cache = GetDebugger().GetSourceFileCache();
|
|
|
|
|
cache.Dump(result.GetOutputStream());
|
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:
1. We always resolve the path.
2. We always check the timestamp.
3. We always recheck the file system for negative cache hits.
D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.
We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:
- The cache at the debugger level works the way it does today. There is
no negative cache: if we can't find the file on disk, we'll try again
next time the cache is queried. If a cached file's timestamp changes
or if its path remapping changes, the cached file is evicted and we
reload it from disk.
- The cache at the process level is design to avoid accessing the file
system. It doesn't check the file's modification time. It caches
negative results, so if a file didn't exist, it doesn't try to reread
it from disk. Checking if the path remapping changed is cheap
(doesn't involve checking the file system) and is the only way for a
file to get evicted from the process cache.
The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.
For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.
In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.
rdar://110787562
Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:06:57 -07:00
|
|
|
|
|
|
|
|
// Dump the process source cache.
|
|
|
|
|
if (ProcessSP process_sp = m_exe_ctx.GetProcessSP()) {
|
|
|
|
|
result.GetOutputStream() << "\nProcess Source File Cache\n";
|
|
|
|
|
SourceManager::SourceFileCache &cache = process_sp->GetSourceFileCache();
|
|
|
|
|
cache.Dump(result.GetOutputStream());
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-26 09:16:23 -07:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishResult);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CommandObjectSourceCacheClear : public CommandObjectParsed {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectSourceCacheClear(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectParsed(interpreter, "source cache clear",
|
|
|
|
|
"Clear the source code cache.\n", nullptr) {}
|
|
|
|
|
|
|
|
|
|
~CommandObjectSourceCacheClear() override = default;
|
|
|
|
|
|
|
|
|
|
protected:
|
2023-10-30 10:21:00 -10:00
|
|
|
void DoExecute(Args &command, CommandReturnObject &result) override {
|
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:
1. We always resolve the path.
2. We always check the timestamp.
3. We always recheck the file system for negative cache hits.
D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.
We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:
- The cache at the debugger level works the way it does today. There is
no negative cache: if we can't find the file on disk, we'll try again
next time the cache is queried. If a cached file's timestamp changes
or if its path remapping changes, the cached file is evicted and we
reload it from disk.
- The cache at the process level is design to avoid accessing the file
system. It doesn't check the file's modification time. It caches
negative results, so if a file didn't exist, it doesn't try to reread
it from disk. Checking if the path remapping changed is cheap
(doesn't involve checking the file system) and is the only way for a
file to get evicted from the process cache.
The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.
For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.
In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.
rdar://110787562
Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:06:57 -07:00
|
|
|
// Clear the debugger cache.
|
2023-06-26 09:16:23 -07:00
|
|
|
SourceManager::SourceFileCache &cache = GetDebugger().GetSourceFileCache();
|
|
|
|
|
cache.Clear();
|
[lldb] Add two-level caching in the source manager
We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:
1. We always resolve the path.
2. We always check the timestamp.
3. We always recheck the file system for negative cache hits.
D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.
We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:
- The cache at the debugger level works the way it does today. There is
no negative cache: if we can't find the file on disk, we'll try again
next time the cache is queried. If a cached file's timestamp changes
or if its path remapping changes, the cached file is evicted and we
reload it from disk.
- The cache at the process level is design to avoid accessing the file
system. It doesn't check the file's modification time. It caches
negative results, so if a file didn't exist, it doesn't try to reread
it from disk. Checking if the path remapping changed is cheap
(doesn't involve checking the file system) and is the only way for a
file to get evicted from the process cache.
The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.
For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.
In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.
rdar://110787562
Differential revision: https://reviews.llvm.org/D153834
2023-07-03 14:06:57 -07:00
|
|
|
|
|
|
|
|
// Clear the process cache.
|
|
|
|
|
if (ProcessSP process_sp = m_exe_ctx.GetProcessSP())
|
|
|
|
|
process_sp->GetSourceFileCache().Clear();
|
|
|
|
|
|
2023-06-26 09:16:23 -07:00
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CommandObjectSourceCache : public CommandObjectMultiword {
|
|
|
|
|
public:
|
|
|
|
|
CommandObjectSourceCache(CommandInterpreter &interpreter)
|
|
|
|
|
: CommandObjectMultiword(interpreter, "source cache",
|
|
|
|
|
"Commands for managing the source code cache.",
|
|
|
|
|
"source cache <sub-command>") {
|
|
|
|
|
LoadSubCommand(
|
|
|
|
|
"dump", CommandObjectSP(new CommandObjectSourceCacheDump(interpreter)));
|
|
|
|
|
LoadSubCommand("clear", CommandObjectSP(new CommandObjectSourceCacheClear(
|
|
|
|
|
interpreter)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CommandObjectSourceCache() override = default;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CommandObjectSourceCache(const CommandObjectSourceCache &) = delete;
|
|
|
|
|
const CommandObjectSourceCache &
|
|
|
|
|
operator=(const CommandObjectSourceCache &) = delete;
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-07 03:36:20 +00:00
|
|
|
#pragma mark CommandObjectMultiwordSource
|
|
|
|
|
// CommandObjectMultiwordSource
|
|
|
|
|
|
2016-07-14 22:03:10 +00:00
|
|
|
CommandObjectMultiwordSource::CommandObjectMultiwordSource(
|
|
|
|
|
CommandInterpreter &interpreter)
|
2019-10-30 15:26:19 -07:00
|
|
|
: CommandObjectMultiword(interpreter, "source",
|
|
|
|
|
"Commands for examining "
|
|
|
|
|
"source code described by "
|
|
|
|
|
"debug information for the "
|
|
|
|
|
"current target process.",
|
2016-07-14 22:03:10 +00:00
|
|
|
"source <subcommand> [<subcommand-options>]") {
|
2016-01-05 19:51:51 +00:00
|
|
|
LoadSubCommand("info",
|
|
|
|
|
CommandObjectSP(new CommandObjectSourceInfo(interpreter)));
|
2010-09-18 01:14:36 +00:00
|
|
|
LoadSubCommand("list",
|
|
|
|
|
CommandObjectSP(new CommandObjectSourceList(interpreter)));
|
2023-06-26 09:16:23 -07:00
|
|
|
LoadSubCommand("cache",
|
|
|
|
|
CommandObjectSP(new CommandObjectSourceCache(interpreter)));
|
2010-07-07 03:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 02:05:55 +00:00
|
|
|
CommandObjectMultiwordSource::~CommandObjectMultiwordSource() = default;
|