aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectSource.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-04-19 04:19:37 +0000
committerGreg Clayton <gclayton@apple.com>2011-04-19 04:19:37 +0000
commit176761e530a96289fb5fed331272bc08ad4acf5b (patch)
treeeabe10abbbacbef5722f61d5687b6d7cd2652286 /lldb/source/Commands/CommandObjectSource.cpp
parent7d6cd4902e9a26b61b65eada1fe8685fbb9e6bac (diff)
downloadllvm-176761e530a96289fb5fed331272bc08ad4acf5b.zip
llvm-176761e530a96289fb5fed331272bc08ad4acf5b.tar.gz
llvm-176761e530a96289fb5fed331272bc08ad4acf5b.tar.bz2
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
Diffstat (limited to 'lldb/source/Commands/CommandObjectSource.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectSource.cpp73
1 files changed, 51 insertions, 22 deletions
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index 4cca075..2e4645e 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -15,11 +15,12 @@
// Project includes
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Debugger.h"
+#include "lldb/Core/FileLineResolver.h"
+#include "lldb/Core/SourceManager.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Target/Process.h"
-#include "lldb/Core/SourceManager.h"
#include "lldb/Target/TargetList.h"
#include "lldb/Interpreter/CommandCompletions.h"
#include "lldb/Interpreter/Options.h"
@@ -28,7 +29,7 @@ using namespace lldb;
using namespace lldb_private;
//-------------------------------------------------------------------------
-// CommandObjectSourceList
+// CommandObjectSourceInfo
//-------------------------------------------------------------------------
class CommandObjectSourceInfo : public CommandObject
@@ -177,7 +178,7 @@ class CommandObjectSourceList : public CommandObject
error.SetErrorStringWithFormat("Invalid line count: '%s'.\n", option_arg);
break;
- case 'f':
+ case 'f':
file_name = option_arg;
break;
@@ -186,7 +187,11 @@ class CommandObjectSourceList : public CommandObject
break;
case 's':
- m_modules.push_back (std::string (option_arg));
+ modules.push_back (std::string (option_arg));
+ break;
+
+ case 'b':
+ show_bp_locs = true;
break;
default:
error.SetErrorStringWithFormat("Unrecognized short option '%c'.\n", short_option);
@@ -204,7 +209,8 @@ class CommandObjectSourceList : public CommandObject
symbol_name.clear();
start_line = 0;
num_lines = 10;
- m_modules.clear();
+ show_bp_locs = false;
+ modules.clear();
}
const OptionDefinition*
@@ -220,7 +226,8 @@ class CommandObjectSourceList : public CommandObject
std::string symbol_name;
uint32_t start_line;
uint32_t num_lines;
- STLStringArray m_modules;
+ STLStringArray modules;
+ bool show_bp_locs;
};
public:
@@ -291,12 +298,12 @@ public:
bool append = true;
size_t num_matches = 0;
- if (m_options.m_modules.size() > 0)
+ if (m_options.modules.size() > 0)
{
ModuleList matching_modules;
- for (unsigned i = 0, e = m_options.m_modules.size(); i != e; i++)
+ for (unsigned i = 0, e = m_options.modules.size(); i != e; i++)
{
- FileSpec module_spec(m_options.m_modules[i].c_str(), false);
+ FileSpec module_spec(m_options.modules[i].c_str(), false);
if (module_spec)
{
matching_modules.Clear();
@@ -408,8 +415,8 @@ public:
m_options.num_lines = end_line - line_no;
}
- char path_buf[PATH_MAX+1];
- start_file.GetPath(path_buf, PATH_MAX);
+ char path_buf[PATH_MAX];
+ start_file.GetPath(path_buf, sizeof(path_buf));
result.AppendMessageWithFormat("File: %s.\n", path_buf);
m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (start_file,
line_no,
@@ -430,7 +437,8 @@ public:
// more likely because you typed it once, then typed it again
if (m_options.start_line == 0)
{
- if (m_interpreter.GetDebugger().GetSourceManager().DisplayMoreWithLineNumbers (&result.GetOutputStream()))
+ if (m_interpreter.GetDebugger().GetSourceManager().DisplayMoreWithLineNumbers (&result.GetOutputStream(),
+ GetBreakpointLocations ()))
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
@@ -442,7 +450,8 @@ public:
0, // Lines before line to display
m_options.num_lines, // Lines after line to display
"", // Don't mark "line"
- &result.GetOutputStream()))
+ &result.GetOutputStream(),
+ GetBreakpointLocations ()))
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
@@ -465,21 +474,21 @@ public:
SymbolContextList sc_list;
size_t num_matches = 0;
- if (m_options.m_modules.size() > 0)
+ if (m_options.modules.size() > 0)
{
ModuleList matching_modules;
- for (unsigned i = 0, e = m_options.m_modules.size(); i != e; i++)
+ for (unsigned i = 0, e = m_options.modules.size(); i != e; i++)
{
- FileSpec module_spec(m_options.m_modules[i].c_str(), false);
+ FileSpec module_spec(m_options.modules[i].c_str(), false);
if (module_spec)
{
matching_modules.Clear();
target->GetImages().FindModules (&module_spec, NULL, NULL, NULL, matching_modules);
num_matches += matching_modules.ResolveSymbolContextForFilePath (filename,
- 0,
- check_inlines,
- eSymbolContextModule | eSymbolContextCompUnit,
- sc_list);
+ 0,
+ check_inlines,
+ eSymbolContextModule | eSymbolContextCompUnit,
+ sc_list);
}
}
}
@@ -535,13 +544,24 @@ public:
{
if (sc.comp_unit)
{
+ if (m_options.show_bp_locs && exe_ctx.target)
+ {
+ const bool show_inlines = true;
+ m_breakpoint_locations.Reset (*sc.comp_unit, 0, show_inlines);
+ SearchFilter target_search_filter (exe_ctx.target->GetSP());
+ target_search_filter.Search (m_breakpoint_locations);
+ }
+ else
+ m_breakpoint_locations.Clear();
+
m_interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (sc.comp_unit,
m_options.start_line,
0,
m_options.num_lines,
"",
- &result.GetOutputStream());
-
+ &result.GetOutputStream(),
+ GetBreakpointLocations ());
+
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
@@ -562,7 +582,15 @@ public:
}
protected:
+ const SymbolContextList *
+ GetBreakpointLocations ()
+ {
+ if (m_breakpoint_locations.GetFileLineMatches().GetSize() > 0)
+ return &m_breakpoint_locations.GetFileLineMatches();
+ return NULL;
+ }
CommandOptions m_options;
+ FileLineResolver m_breakpoint_locations;
};
@@ -571,6 +599,7 @@ CommandObjectSourceList::CommandOptions::g_option_table[] =
{
{ LLDB_OPT_SET_ALL, false, "count", 'c', required_argument, NULL, 0, eArgTypeCount, "The number of source lines to display."},
{ LLDB_OPT_SET_ALL, false, "shlib", 's', required_argument, NULL, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Look up the source file in the given shared library."},
+{ LLDB_OPT_SET_ALL, false, "show-breakpoints", 'b', no_argument, NULL, 0, eArgTypeNone, "Show the line table locations from the debug information that indicate valid places to set source level breakpoints."},
{ LLDB_OPT_SET_1, false, "file", 'f', required_argument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "The file from which to display source."},
{ LLDB_OPT_SET_1, false, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, "The line number at which to start the display source."},
{ LLDB_OPT_SET_2, false, "name", 'n', required_argument, NULL, CommandCompletions::eSymbolCompletion, eArgTypeSymbol, "The name of a function whose source to display."},