[Lldb-commits] [lldb] r129747 - in /lldb/trunk: include/lldb/Breakpoint/ include/lldb/Core/ include/lldb/Symbol/ lldb.xcodeproj/ source/Commands/ source/Core/ source/Symbol/

Greg Clayton gclayton at apple.com
Mon Apr 18 21:19:37 PDT 2011


Author: gclayton
Date: Mon Apr 18 23:19:37 2011
New Revision: 129747

URL: http://llvm.org/viewvc/llvm-project?rev=129747&view=rev
Log:
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.


Added:
    lldb/trunk/include/lldb/Core/FileLineResolver.h
    lldb/trunk/source/Core/FileLineResolver.cpp
Modified:
    lldb/trunk/include/lldb/Breakpoint/BreakpointResolverFileLine.h
    lldb/trunk/include/lldb/Core/SearchFilter.h
    lldb/trunk/include/lldb/Core/SourceManager.h
    lldb/trunk/include/lldb/Symbol/LineTable.h
    lldb/trunk/include/lldb/Symbol/SymbolContext.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
    lldb/trunk/source/Commands/CommandObjectSource.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/AddressResolverFileLine.cpp
    lldb/trunk/source/Core/SearchFilter.cpp
    lldb/trunk/source/Core/SourceManager.cpp
    lldb/trunk/source/Symbol/LineTable.cpp
    lldb/trunk/source/Symbol/SymbolContext.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointResolverFileLine.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointResolverFileLine.h?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointResolverFileLine.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointResolverFileLine.h Mon Apr 18 23:19:37 2011
@@ -29,9 +29,9 @@
 {
 public:
     BreakpointResolverFileLine (Breakpoint *bkpt,
-                           const FileSpec &resolver,
-                           uint32_t line_no,
-                           bool check_inlines);
+                                const FileSpec &resolver,
+                                uint32_t line_no,
+                                bool check_inlines);
 
     virtual
     ~BreakpointResolverFileLine ();

Added: lldb/trunk/include/lldb/Core/FileLineResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FileLineResolver.h?rev=129747&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/FileLineResolver.h (added)
+++ lldb/trunk/include/lldb/Core/FileLineResolver.h Mon Apr 18 23:19:37 2011
@@ -0,0 +1,80 @@
+//===-- FileLineResolver.h --------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_FileLineResolver_h_
+#define liblldb_FileLineResolver_h_
+
+// Project includes
+#include "lldb/Core/AddressResolver.h"
+
+namespace lldb_private {
+
+//----------------------------------------------------------------------
+/// @class FileLineResolver FileLineResolver.h "lldb/Core/FileLineResolver.h"
+/// @brief This class finds address for source file and line.  Optionally, it will look for inlined
+/// instances of the file and line specification.
+//----------------------------------------------------------------------
+
+class FileLineResolver :
+    public Searcher
+{
+public:
+    FileLineResolver () :
+        m_file_spec(),
+        m_line_number(UINT32_MAX), // Set this to zero for all lines in a file
+        m_sc_list (),
+        m_inlines (true)
+    {
+    }
+        
+    FileLineResolver (const FileSpec &resolver,
+                      uint32_t line_no,
+                      bool check_inlines);
+
+    virtual
+    ~FileLineResolver ();
+
+    virtual Searcher::CallbackReturn
+    SearchCallback (SearchFilter &filter,
+                    SymbolContext &context,
+                    Address *addr,
+                    bool containing);
+
+    virtual Searcher::Depth
+    GetDepth ();
+
+    virtual void
+    GetDescription (Stream *s);
+
+    const SymbolContextList &
+    GetFileLineMatches()
+    {
+        return m_sc_list;
+    }
+
+    void
+    Clear();
+
+    void
+    Reset (const FileSpec &file_spec,
+           uint32_t line,
+           bool check_inlines);
+protected:    
+    FileSpec m_file_spec; // This is the file spec we are looking for.
+    uint32_t m_line_number; // This is the line number that we are looking for.
+    SymbolContextList m_sc_list;
+    bool m_inlines; // This determines whether the resolver looks for inlined functions or not.
+
+private:
+    DISALLOW_COPY_AND_ASSIGN(FileLineResolver);
+};
+
+} // namespace lldb_private
+
+#endif  // liblldb_FileLineResolver_h_

Modified: lldb/trunk/include/lldb/Core/SearchFilter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SearchFilter.h?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SearchFilter.h (original)
+++ lldb/trunk/include/lldb/Core/SearchFilter.h Mon Apr 18 23:19:37 2011
@@ -105,9 +105,9 @@
     /// @param[in] target
     ///    The Target that provides the module list to search.
     //------------------------------------------------------------------
-    SearchFilter (lldb::TargetSP &target_sp);
+    SearchFilter (const lldb::TargetSP &target_sp);
 
-    SearchFilter(const SearchFilter& rhs);
+    SearchFilter (const SearchFilter& rhs);
 
     virtual
     ~SearchFilter ();

Modified: lldb/trunk/include/lldb/Core/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/SourceManager.h?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/SourceManager.h (original)
+++ lldb/trunk/include/lldb/Core/SourceManager.h Mon Apr 18 23:19:37 2011
@@ -86,18 +86,21 @@
                                        uint32_t context_before,
                                        uint32_t context_after,
                                        const char* current_line_cstr,
-                                       Stream *s);
+                                       Stream *s,
+                                       const SymbolContextList *bp_locs = NULL);
 
     // This variant uses the last file we visited.
     size_t
     DisplaySourceLinesWithLineNumbersUsingLastFile (uint32_t line,
-                                       uint32_t context_before,
-                                       uint32_t context_after,
-                                       const char* current_line_cstr,
-                                       Stream *s);
+                                                    uint32_t context_before,
+                                                    uint32_t context_after,
+                                                    const char* current_line_cstr,
+                                                    Stream *s,
+                                                    const SymbolContextList *bp_locs = NULL);
 
     size_t
-    DisplayMoreWithLineNumbers (Stream *s);
+    DisplayMoreWithLineNumbers (Stream *s,
+                                const SymbolContextList *bp_locs = NULL);
 
 protected:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Symbol/LineTable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/LineTable.h?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/LineTable.h (original)
+++ lldb/trunk/include/lldb/Symbol/LineTable.h Mon Apr 18 23:19:37 2011
@@ -91,10 +91,15 @@
     /// @see Address::DumpStyle
     //------------------------------------------------------------------
     void
-    Dump (Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_line_ranges);
+    Dump (Stream *s, Target *target, 
+          Address::DumpStyle style, 
+          Address::DumpStyle fallback_style, 
+          bool show_line_ranges);
 
     void
-    GetDescription (Stream *s, Target *target, lldb::DescriptionLevel level);
+    GetDescription (Stream *s, 
+                    Target *target, 
+                    lldb::DescriptionLevel level);
 
     //------------------------------------------------------------------
     /// Find a line entry that contains the section offset address \a
@@ -156,7 +161,11 @@
     /// @see FileSpecList::FindFileIndex (uint32_t, const FileSpec &) const
     //------------------------------------------------------------------
     uint32_t
-    FindLineEntryIndexByFileIndex (uint32_t start_idx, uint32_t file_idx, uint32_t line, bool exact, LineEntry* line_entry_ptr);
+    FindLineEntryIndexByFileIndex (uint32_t start_idx, 
+                                   uint32_t file_idx, 
+                                   uint32_t line, 
+                                   bool exact, 
+                                   LineEntry* line_entry_ptr);
 
     uint32_t
     FindLineEntryIndexByFileIndex (uint32_t start_idx, 
@@ -165,6 +174,11 @@
                                    bool exact, 
                                    LineEntry* line_entry_ptr);
 
+    size_t
+    FineLineEntriesForFileIndex (uint32_t file_idx, 
+                                 bool append,
+                                 SymbolContextList &sc_list);
+
     //------------------------------------------------------------------
     /// Get the line entry from the line table at index \a idx.
     ///

Modified: lldb/trunk/include/lldb/Symbol/SymbolContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolContext.h Mon Apr 18 23:19:37 2011
@@ -400,6 +400,9 @@
     uint32_t
     GetSize() const;
 
+    uint32_t
+    NumLineEntriesWithLine (uint32_t line) const;
+    
 protected:
     typedef std::vector<SymbolContext> collection; ///< The collection type for the list.
 

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Mon Apr 18 23:19:37 2011
@@ -377,6 +377,7 @@
 		26B1FCBD13381071002886E2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C74CB6212288704006A8171 /* Carbon.framework */; };
 		26B1FCC21338115F002886E2 /* Host.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7EE810F1B88F00F91463 /* Host.mm */; };
 		26B42C4D1187ABA50079C8C8 /* LLDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 26B42C4C1187ABA50079C8C8 /* LLDB.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		26BD407F135D2AE000237D80 /* FileLineResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BD407E135D2ADF00237D80 /* FileLineResolver.cpp */; };
 		26C72C94124322890068DC16 /* SBStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 26C72C93124322890068DC16 /* SBStream.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		26C72C961243229A0068DC16 /* SBStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C72C951243229A0068DC16 /* SBStream.cpp */; };
 		26D5E15F135BAEA2006EA0A7 /* OptionGroupArchitecture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26D5E15E135BAEA2006EA0A7 /* OptionGroupArchitecture.cpp */; };
@@ -965,6 +966,8 @@
 		26BC7F3E10F1B90C00F91463 /* ThreadList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadList.cpp; path = source/Target/ThreadList.cpp; sourceTree = "<group>"; };
 		26BC7F3F10F1B90C00F91463 /* ThreadPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadPlan.cpp; path = source/Target/ThreadPlan.cpp; sourceTree = "<group>"; };
 		26BC7F4C10F1BC1A00F91463 /* ObjectFile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectFile.cpp; path = source/Symbol/ObjectFile.cpp; sourceTree = "<group>"; };
+		26BD407D135D2AC400237D80 /* FileLineResolver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FileLineResolver.h; path = include/lldb/Core/FileLineResolver.h; sourceTree = "<group>"; };
+		26BD407E135D2ADF00237D80 /* FileLineResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileLineResolver.cpp; path = source/Core/FileLineResolver.cpp; sourceTree = "<group>"; };
 		26C5577B132575AD008FD8FE /* PlatformMacOSX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformMacOSX.cpp; sourceTree = "<group>"; };
 		26C5577C132575AD008FD8FE /* PlatformMacOSX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformMacOSX.h; sourceTree = "<group>"; };
 		26C72C93124322890068DC16 /* SBStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBStream.h; path = include/lldb/API/SBStream.h; sourceTree = "<group>"; };
@@ -1847,6 +1850,8 @@
 				26BC7E7810F1B85900F91463 /* Error.cpp */,
 				26BC7D6110F1B77400F91463 /* Event.h */,
 				26BC7E7910F1B85900F91463 /* Event.cpp */,
+				26BD407D135D2AC400237D80 /* FileLineResolver.h */,
+				26BD407E135D2ADF00237D80 /* FileLineResolver.cpp */,
 				26BC7D6310F1B77400F91463 /* FileSpecList.h */,
 				26BC7E7B10F1B85900F91463 /* FileSpecList.cpp */,
 				26BC7D6410F1B77400F91463 /* Flags.h */,
@@ -3136,6 +3141,7 @@
 				4CD0BD0F134BFADF00CB44D4 /* ValueObjectDynamicValue.cpp in Sources */,
 				26D5E15F135BAEA2006EA0A7 /* OptionGroupArchitecture.cpp in Sources */,
 				26D5E163135BB054006EA0A7 /* OptionGroupPlatform.cpp in Sources */,
+				26BD407F135D2AE000237D80 /* FileLineResolver.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Mon Apr 18 23:19:37 2011
@@ -337,13 +337,10 @@
                     }
                     else
                     {
-                        const SymbolContext &context = cur_frame->GetSymbolContext(true);
-                        if (context.line_entry.file)
+                        const SymbolContext &sc = cur_frame->GetSymbolContext (eSymbolContextLineEntry);
+                        if (sc.line_entry.file)
                         {
-                            file = context.line_entry.file;
-                        }
-                        else if (context.comp_unit != NULL)
-                        {    file = context.comp_unit;
+                            file = sc.line_entry.file;
                         }
                         else
                         {

Modified: lldb/trunk/source/Commands/CommandObjectSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSource.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSource.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSource.cpp Mon Apr 18 23:19:37 2011
@@ -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_private;
 
 //-------------------------------------------------------------------------
-// CommandObjectSourceList
+// CommandObjectSourceInfo
 //-------------------------------------------------------------------------
 
 class CommandObjectSourceInfo : public CommandObject
@@ -177,7 +178,7 @@
                     error.SetErrorStringWithFormat("Invalid line count: '%s'.\n", option_arg);
                 break;
 
-             case 'f':
+            case 'f':
                 file_name = option_arg;
                 break;
                 
@@ -186,7 +187,11 @@
                 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 @@
             symbol_name.clear();
             start_line = 0;
             num_lines = 10;
-            m_modules.clear();
+            show_bp_locs = false;
+            modules.clear();
         }
 
         const OptionDefinition*
@@ -220,7 +226,8 @@
         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 @@
             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 @@
                     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 @@
             // 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 @@
                             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 @@
             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 @@
             {
                 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 @@
     }
 
 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 @@
 {
 { 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."},

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Mon Apr 18 23:19:37 2011
@@ -37,7 +37,7 @@
 static void
 DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
 {
-    ArchSpec &target_arch = target->GetArchitecture();
+    const ArchSpec &target_arch = target->GetArchitecture();
     
     ModuleSP exe_module_sp (target->GetExecutableModule ());
     char exe_path[PATH_MAX];

Modified: lldb/trunk/source/Core/AddressResolverFileLine.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/AddressResolverFileLine.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Core/AddressResolverFileLine.cpp (original)
+++ lldb/trunk/source/Core/AddressResolverFileLine.cpp Mon Apr 18 23:19:37 2011
@@ -23,7 +23,7 @@
 AddressResolverFileLine::AddressResolverFileLine
 (
     const FileSpec &file_spec,
-        uint32_t line_no,
+    uint32_t line_no,
     bool check_inlines
 ) :
     AddressResolver (),
@@ -42,7 +42,7 @@
 (
     SearchFilter &filter,
     SymbolContext &context,
-        Address *addr,
+    Address *addr,
     bool containing
 )
 {

Added: lldb/trunk/source/Core/FileLineResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileLineResolver.cpp?rev=129747&view=auto
==============================================================================
--- lldb/trunk/source/Core/FileLineResolver.cpp (added)
+++ lldb/trunk/source/Core/FileLineResolver.cpp Mon Apr 18 23:19:37 2011
@@ -0,0 +1,118 @@
+//===-- FileLineResolver.cpp ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/FileLineResolver.h"
+
+// Project includes
+#include "lldb/lldb-private-log.h"
+#include "lldb/Core/Log.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Symbol/LineTable.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//----------------------------------------------------------------------
+// FileLineResolver:
+//----------------------------------------------------------------------
+FileLineResolver::FileLineResolver
+(
+    const FileSpec &file_spec,
+    uint32_t line_no,
+    bool check_inlines
+) :
+    Searcher (),
+    m_file_spec (file_spec),
+    m_line_number (line_no),
+    m_inlines (check_inlines)
+{
+}
+
+FileLineResolver::~FileLineResolver ()
+{
+}
+
+Searcher::CallbackReturn
+FileLineResolver::SearchCallback
+(
+    SearchFilter &filter,
+    SymbolContext &context,
+    Address *addr,
+    bool containing
+)
+{
+    CompileUnit *cu = context.comp_unit;
+
+    if (m_inlines || m_file_spec.Compare(*cu, m_file_spec, m_file_spec.GetDirectory()))
+    {
+        uint32_t start_file_idx = 0;
+        uint32_t file_idx = cu->GetSupportFiles().FindFileIndex(start_file_idx, m_file_spec);
+        if (file_idx != UINT32_MAX)
+        {
+            LineTable *line_table = cu->GetLineTable();
+            if (line_table)
+            {
+                if (m_line_number == 0)
+                {
+                    // Match all lines in a file...
+                    const bool append = true;
+                    while (file_idx != UINT32_MAX)
+                    {
+                        line_table->FineLineEntriesForFileIndex (file_idx, append, m_sc_list);
+                        // Get the next file index in case we have multiple file 
+                        // entries for the same file
+                        file_idx = cu->GetSupportFiles().FindFileIndex(file_idx + 1, m_file_spec);
+                    }
+                }
+                else
+                {
+                    // Match a specific line in a file...
+                }
+            }
+        }
+    }
+    return Searcher::eCallbackReturnContinue;
+}
+
+Searcher::Depth
+FileLineResolver::GetDepth()
+{
+    return Searcher::eDepthCompUnit;
+}
+
+void
+FileLineResolver::GetDescription (Stream *s)
+{
+    s->Printf ("File and line resolver for file: \"%s%s%s\" line: %u", 
+               m_file_spec.GetDirectory().GetCString(),
+               m_file_spec.GetDirectory() ? "/" : "",
+               m_file_spec.GetFilename().GetCString(),
+               m_line_number);
+}
+
+void
+FileLineResolver::Clear()
+{
+    m_file_spec.Clear();
+    m_line_number = UINT32_MAX;
+    m_sc_list.Clear();
+    m_inlines = true;
+}
+
+void
+FileLineResolver::Reset (const FileSpec &file_spec,
+                         uint32_t line,
+                         bool check_inlines)
+{
+    m_file_spec = file_spec;
+    m_line_number = line;
+    m_sc_list.Clear();
+    m_inlines = check_inlines;
+}
+

Modified: lldb/trunk/source/Core/SearchFilter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SearchFilter.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Core/SearchFilter.cpp (original)
+++ lldb/trunk/source/Core/SearchFilter.cpp Mon Apr 18 23:19:37 2011
@@ -40,7 +40,7 @@
 //----------------------------------------------------------------------
 // SearchFilter constructor
 //----------------------------------------------------------------------
-SearchFilter::SearchFilter(lldb::TargetSP &target_sp) :
+SearchFilter::SearchFilter(const TargetSP &target_sp) :
     m_target_sp (target_sp)
 {
 }

Modified: lldb/trunk/source/Core/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/SourceManager.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Core/SourceManager.cpp (original)
+++ lldb/trunk/source/Core/SourceManager.cpp Mon Apr 18 23:19:37 2011
@@ -15,6 +15,7 @@
 // Project includes
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/Stream.h"
+#include "lldb/Symbol/SymbolContext.h"
 
 using namespace lldb_private;
 
@@ -85,7 +86,8 @@
     uint32_t context_before,
     uint32_t context_after,
     const char* current_line_cstr,
-    Stream *s
+    Stream *s,
+    const SymbolContextList *bp_locs
 )
 {
     if (line == 0)
@@ -119,7 +121,21 @@
                 break;
             }
 
-            s->Printf("%2.2s %-4u\t", curr_line == line ? current_line_cstr : "", curr_line);
+            char prefix[32] = "";
+            if (bp_locs)
+            {
+                uint32_t bp_count = bp_locs->NumLineEntriesWithLine (curr_line);
+                
+                if (bp_count > 0)
+                    ::snprintf (prefix, sizeof (prefix), "[%u] ", bp_count);
+                else
+                    ::snprintf (prefix, sizeof (prefix), "    ");
+            }
+
+            s->Printf("%s%2.2s %-4u\t", 
+                      prefix,
+                      curr_line == line ? current_line_cstr : "", 
+                      curr_line);
             if (m_last_file_sp->DisplaySourceLines (curr_line, 0, 0, s) == 0)
             {
                 m_last_file_line = UINT32_MAX;
@@ -138,7 +154,8 @@
     uint32_t context_before,
     uint32_t context_after,
     const char* current_line_cstr,
-    Stream *s
+    Stream *s,
+    const SymbolContextList *bp_locs
 )
 {
     bool same_as_previous = m_last_file_sp && m_last_file_sp->FileSpecMatches (file_spec);
@@ -152,17 +169,17 @@
             m_last_file_line = 0;
     }
 
-    return DisplaySourceLinesWithLineNumbersUsingLastFile (line, context_before, context_after, current_line_cstr, s);
+    return DisplaySourceLinesWithLineNumbersUsingLastFile (line, context_before, context_after, current_line_cstr, s, bp_locs);
 }
 
 size_t
-SourceManager::DisplayMoreWithLineNumbers (Stream *s)
+SourceManager::DisplayMoreWithLineNumbers (Stream *s, const SymbolContextList *bp_locs)
 {
     if (m_last_file_sp)
     {
         if (m_last_file_line == UINT32_MAX)
             return 0;
-        DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s);
+        DisplaySourceLinesWithLineNumbersUsingLastFile (0, m_last_file_context_before, m_last_file_context_after, "", s, bp_locs);
     }
     return 0;
 }

Modified: lldb/trunk/source/Symbol/LineTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/LineTable.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/LineTable.cpp (original)
+++ lldb/trunk/source/Symbol/LineTable.cpp Mon Apr 18 23:19:37 2011
@@ -378,6 +378,41 @@
     return UINT32_MAX;
 }
 
+size_t
+LineTable::FineLineEntriesForFileIndex (uint32_t file_idx, 
+                                        bool append,
+                                        SymbolContextList &sc_list)
+{
+    
+    if (!append)
+        sc_list.Clear();
+
+    size_t num_added = 0;
+    const size_t count = m_entries.size();
+    if (count > 0)
+    {
+        SymbolContext sc (m_comp_unit);
+
+        for (size_t idx = 0; idx < count; ++idx)
+        {
+            // Skip line table rows that terminate the previous row (is_terminal_entry is non-zero)
+            if (m_entries[idx].is_terminal_entry)
+                continue;
+            
+            if (m_entries[idx].file_idx == file_idx)
+            {
+                if (ConvertEntryAtIndexToLineEntry (idx, sc.line_entry))
+                {
+                    ++num_added;
+                    sc_list.Append(sc);
+                }
+            }
+        }
+    }
+    return num_added;
+}
+
+
 void
 LineTable::Dump (Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_line_ranges)
 {

Modified: lldb/trunk/source/Symbol/SymbolContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=129747&r1=129746&r2=129747&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolContext.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolContext.cpp Mon Apr 18 23:19:37 2011
@@ -842,3 +842,17 @@
 {
     return m_symbol_contexts.size();
 }
+
+uint32_t
+SymbolContextList::NumLineEntriesWithLine (uint32_t line) const
+{
+    uint32_t match_count = 0;
+    const uint32_t size = m_symbol_contexts.size();
+    for (uint32_t idx = 0; idx<size; ++idx)
+    {
+        if (m_symbol_contexts[idx].line_entry.line == line)
+            ++match_count;
+    }
+    return match_count;
+}
+





More information about the lldb-commits mailing list