[Lldb-commits] [lldb] r115485 - in /lldb/trunk: include/lldb/Core/ include/lldb/Target/ source/API/ source/Commands/ source/Core/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/ source/Target/

Greg Clayton gclayton at apple.com
Sun Oct 3 18:05:56 PDT 2010


Author: gclayton
Date: Sun Oct  3 20:05:56 2010
New Revision: 115485

URL: http://llvm.org/viewvc/llvm-project?rev=115485&view=rev
Log:
There are now to new "settings set" variables that live in each debugger
instance:

settings set frame-format <string>
settings set thread-format <string>

This allows users to control the information that is seen when dumping
threads and frames. The default values are set such that they do what they
used to do prior to changing over the the user defined formats.

This allows users with terminals that can display color to make different
items different colors using the escape control codes. A few alias examples
that will colorize your thread and frame prompts are:

settings set frame-format 'frame #${frame.index}: \033[0;33m${frame.pc}\033[0m{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{ \033[0;35mat \033[1;35m${line.file.basename}:${line.number}}\033[0m\n'

settings set thread-format 'thread #${thread.index}: \033[1;33mtid\033[0;33m = ${thread.id}\033[0m{, \033[0;33m${frame.pc}\033[0m}{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{, \033[1;35mstop reason\033[0;35m = ${thread.stop-reason}\033[0m}{, \033[1;36mname = \033[0;36m${thread.name}\033[0m}{, \033[1;32mqueue = \033[0;32m${thread.queue}}\033[0m\n'

A quick web search for "colorize terminal output" should allow you to see what
you can do to make your output look like you want it.

The "settings set" commands above can of course be added to your ~/.lldbinit
file for permanent use.

Changed the pure virtual 
    void ExecutionContextScope::Calculate (ExecutionContext&);
To:
    void ExecutionContextScope::CalculateExecutionContext (ExecutionContext&);
    
I did this because this is a class that anything in the execution context
heirarchy inherits from and "target->Calculate (exe_ctx)" didn't always tell
you what it was really trying to do unless you look at the parameter.



Modified:
    lldb/trunk/include/lldb/Core/Debugger.h
    lldb/trunk/include/lldb/Target/ExecutionContextScope.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/include/lldb/Target/RegisterContext.h
    lldb/trunk/include/lldb/Target/StackFrame.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/include/lldb/Target/Thread.h
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SBThread.cpp
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Commands/CommandObjectFrame.cpp
    lldb/trunk/source/Commands/CommandObjectThread.cpp
    lldb/trunk/source/Core/Address.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCRuntimeV2.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCTrampolineHandler.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleThreadPlanStepThroughObjCTrampoline.cpp
    lldb/trunk/source/Target/ExecutionContext.cpp
    lldb/trunk/source/Target/Process.cpp
    lldb/trunk/source/Target/RegisterContext.cpp
    lldb/trunk/source/Target/StackFrame.cpp
    lldb/trunk/source/Target/StackFrameList.cpp
    lldb/trunk/source/Target/StopInfo.cpp
    lldb/trunk/source/Target/Target.cpp
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/include/lldb/Core/Debugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Debugger.h (original)
+++ lldb/trunk/include/lldb/Core/Debugger.h Sun Oct  3 20:05:56 2010
@@ -93,7 +93,41 @@
             m_prompt.assign ("(lldb) ");
         BroadcastPromptChange (m_instance_name, m_prompt.c_str());
     }
-        
+
+    const char *
+    GetFrameFormat() const
+    {
+        return m_frame_format.c_str();
+    }
+
+    bool
+    SetFrameFormat(const char *frame_format)
+    {
+        if (frame_format && frame_format[0])
+        {
+            m_frame_format.assign (frame_format);
+            return true;
+        }
+        return false;
+    }
+
+    const char *
+    GetThreadFormat() const
+    {
+        return m_thread_format.c_str();
+    }
+
+    bool
+    SetThreadFormat(const char *thread_format)
+    {
+        if (thread_format && thread_format[0])
+        {
+            m_thread_format.assign (thread_format);
+            return true;
+        }
+        return false;
+    }
+
     lldb::ScriptLanguage 
     GetScriptLanguage() const
     {
@@ -139,6 +173,12 @@
     PromptVarName ();
 
     static const ConstString &
+    GetFrameFormatName ();
+
+    static const ConstString &
+    GetThreadFormatName ();
+
+    static const ConstString &
     ScriptLangVarName ();
   
     static const ConstString &
@@ -151,6 +191,8 @@
 
     uint32_t m_term_width;
     std::string m_prompt;
+    std::string m_frame_format;
+    std::string m_thread_format;
     lldb::ScriptLanguage m_script_lang;
     bool m_use_external_editor;
 };

Modified: lldb/trunk/include/lldb/Target/ExecutionContextScope.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ExecutionContextScope.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ExecutionContextScope.h (original)
+++ lldb/trunk/include/lldb/Target/ExecutionContextScope.h Sun Oct  3 20:05:56 2010
@@ -63,7 +63,7 @@
     ///     in.
     //------------------------------------------------------------------
     virtual void
-    Calculate (ExecutionContext &exe_ctx) = 0;
+    CalculateExecutionContext (ExecutionContext &exe_ctx) = 0;
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Sun Oct  3 20:05:56 2010
@@ -1589,7 +1589,7 @@
     CalculateStackFrame ();
 
     virtual void
-    Calculate (ExecutionContext &exe_ctx);
+    CalculateExecutionContext (ExecutionContext &exe_ctx);
     
     lldb::ProcessSP
     GetSP ();

Modified: lldb/trunk/include/lldb/Target/RegisterContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/RegisterContext.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/RegisterContext.h (original)
+++ lldb/trunk/include/lldb/Target/RegisterContext.h Sun Oct  3 20:05:56 2010
@@ -161,7 +161,7 @@
     CalculateStackFrame ();
 
     virtual void
-    Calculate (ExecutionContext &exe_ctx);
+    CalculateExecutionContext (ExecutionContext &exe_ctx);
 
 protected:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Target/StackFrame.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/StackFrame.h (original)
+++ lldb/trunk/include/lldb/Target/StackFrame.h Sun Oct  3 20:05:56 2010
@@ -103,6 +103,9 @@
     Disassemble ();
 
     void
+    DumpUsingSettingsFormat (Stream *strm);
+    
+    void
     Dump (Stream *strm, bool show_frame_index, bool show_fullpaths);
     
     bool
@@ -142,7 +145,7 @@
     CalculateStackFrame ();
 
     virtual void
-    Calculate (ExecutionContext &exe_ctx);
+    CalculateExecutionContext (ExecutionContext &exe_ctx);
     
     lldb::StackFrameSP
     GetSP ();

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Sun Oct  3 20:05:56 2010
@@ -402,6 +402,11 @@
         return m_section_load_list;
     }
 
+
+    static Target *
+    GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 
+                           const SymbolContext *sc_ptr);
+
     //------------------------------------------------------------------
     // lldb::ExecutionContextScope pure virtual functions
     //------------------------------------------------------------------
@@ -418,7 +423,7 @@
     CalculateStackFrame ();
 
     virtual void
-    Calculate (ExecutionContext &exe_ctx);
+    CalculateExecutionContext (ExecutionContext &exe_ctx);
 
     PathMappingList &
     GetImageSearchPathList ();

Modified: lldb/trunk/include/lldb/Target/Thread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Thread.h (original)
+++ lldb/trunk/include/lldb/Target/Thread.h Sun Oct  3 20:05:56 2010
@@ -287,11 +287,7 @@
     ClearStackFrames ();
 
     void
-    DumpInfo (Stream &strm,
-              bool show_stop_reason,
-              bool show_name,
-              bool show_queue,
-              uint32_t frame_idx);// = UINT32_MAX);
+    DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx);
 
     //------------------------------------------------------------------
     // Thread Plan Providers:
@@ -613,7 +609,7 @@
     CalculateStackFrame ();
 
     virtual void
-    Calculate (ExecutionContext &exe_ctx);
+    CalculateExecutionContext (ExecutionContext &exe_ctx);
     
     lldb::StackFrameSP
     GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr);

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Sun Oct  3 20:05:56 2010
@@ -395,7 +395,7 @@
     if (m_opaque_sp)
     {
         description.ref();
-        m_opaque_sp->Dump (description.get(), true, false);
+        m_opaque_sp->DumpUsingSettingsFormat (description.get());
     }
     else
         description.Printf ("No value");

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Sun Oct  3 20:05:56 2010
@@ -431,9 +431,9 @@
         ExecutionContext exe_ctx;
 
         if (process)
-            process->Calculate(exe_ctx);
+            process->CalculateExecutionContext(exe_ctx);
         else 
-            m_opaque_sp->Calculate(exe_ctx);
+            m_opaque_sp->CalculateExecutionContext(exe_ctx);
 
         if (end_addr == LLDB_INVALID_ADDRESS || end_addr < start_addr)
             range.SetByteSize( DEFAULT_DISASM_BYTE_SIZE);
@@ -484,9 +484,9 @@
             process = NULL;
         
         if (process)
-            process->Calculate(exe_ctx);
+            process->CalculateExecutionContext(exe_ctx);
         else 
-            m_opaque_sp->Calculate(exe_ctx);
+            m_opaque_sp->CalculateExecutionContext(exe_ctx);
 
 
         StreamFile out_stream (out);

Modified: lldb/trunk/source/API/SBThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/API/SBThread.cpp (original)
+++ lldb/trunk/source/API/SBThread.cpp Sun Oct  3 20:05:56 2010
@@ -419,7 +419,7 @@
 {
     if (m_opaque_sp)
     {
-        m_opaque_sp->DumpInfo (description.ref(), true, true, true, LLDB_INVALID_INDEX32);
+        m_opaque_sp->DumpUsingSettingsFormat (description.ref(), LLDB_INVALID_INDEX32);
         description.Printf (" %d frames, (instance name: %s)", GetNumFrames(), 
                             m_opaque_sp->GetInstanceName().AsCString());
     }

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Sun Oct  3 20:05:56 2010
@@ -70,14 +70,10 @@
                 // char '#'
                 while (pos != commands.end())
                 {
-                    bool remove_string = false;
                     size_t non_space = pos->find_first_not_of (k_space_characters);
-                    if (non_space == std::string::npos)
-                        remove_string = true; // Empty line
-                    else if ((*pos)[non_space] == '#')
-                        remove_string = true; // Comment line that starts with '#'
-
-                    if (remove_string)
+                    // Check for empty line or comment line (lines whose first
+                    // non-space character is a '#')
+                    if (non_space == std::string::npos || (*pos)[non_space] == '#')
                         pos = commands.erase(pos);
                     else
                         ++pos;

Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Sun Oct  3 20:05:56 2010
@@ -71,7 +71,7 @@
         ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
         if (exe_ctx.frame)
         {
-            exe_ctx.frame->Dump (&result.GetOutputStream(), true, false);
+            exe_ctx.frame->DumpUsingSettingsFormat (&result.GetOutputStream());
             result.GetOutputStream().EOL();
             result.SetStatus (eReturnStatusSuccessFinishResult);
         }

Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Sun Oct  3 20:05:56 2010
@@ -80,13 +80,7 @@
         }
         else
         {
-            thread->DumpInfo (strm,
-                              true, // Dump the stop reason?
-                              true, // Dump the thread name?
-                              true, // Dump the queue name?
-                              0);   // Display context info for stack frame zero
-
-            strm.EOL();
+            thread->DumpUsingSettingsFormat (strm, 0);
         }
 
         return true;
@@ -164,12 +158,7 @@
     if (num_frames == 0)
         return 0;
     
-    thread->DumpInfo (strm,
-                      true,     // Dump the stop reason?
-                      true,     // Dump the thread name?
-                      true,     // Dump the queue name?
-                      num_frames > 1 ? UINT32_MAX : first_frame);  // Dump info for the first stack frame if we are showing only on frame
-    strm.EOL();
+    thread->DumpUsingSettingsFormat (strm, num_frames > 1 ? UINT32_MAX : first_frame);
     strm.IndentMore();
 
     StackFrameSP frame_sp;
@@ -224,8 +213,7 @@
         if (show_frame_info)
         {
             strm.Indent();
-            frame->Dump (&strm, true, false);
-            strm.EOL();
+            frame->DumpUsingSettingsFormat (&strm);
         }
 
         SymbolContext sc (frame->GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry));

Modified: lldb/trunk/source/Core/Address.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Core/Address.cpp (original)
+++ lldb/trunk/source/Core/Address.cpp Sun Oct  3 20:05:56 2010
@@ -140,7 +140,7 @@
     if (success)
     {
         ExecutionContext exe_ctx;
-        exe_scope->Calculate(exe_ctx);
+        exe_scope->CalculateExecutionContext(exe_ctx);
         // If we have any sections that are loaded, try and resolve using the
         // section load list
         if (exe_ctx.target && !exe_ctx.target->GetSectionLoadList().IsEmpty())

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Sun Oct  3 20:05:56 2010
@@ -622,7 +622,7 @@
 
     SymbolContext sc (frame->GetSymbolContext(eSymbolContextEverything));
     ExecutionContext exe_ctx;
-    frame->Calculate(exe_ctx);
+    frame->CalculateExecutionContext(exe_ctx);
     const char *end = NULL;
     if (Debugger::FormatPrompt (prompt_format, &sc, &exe_ctx, &sc.line_entry.range.GetBaseAddress(), s, &end))
     {
@@ -814,12 +814,9 @@
                             }
                             else if (::strncmp (var_name_begin, "target.", strlen("target.")) == 0)
                             {
-                                if (sc->target_sp || (exe_ctx && exe_ctx->process))
+                                Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
+                                if (target)
                                 {
-                                    Target *target = sc->target_sp.get();
-                                    if (target == NULL)
-                                        target = &exe_ctx->process->GetTarget();
-                                    assert (target);
                                     var_name_begin += ::strlen ("target.");
                                     if (::strncmp (var_name_begin, "arch}", strlen("arch}")) == 0)
                                     {
@@ -838,10 +835,9 @@
                         case 'm':
                             if (::strncmp (var_name_begin, "module.", strlen("module.")) == 0)
                             {
-                                Module *module = sc->module_sp.get();
-                                
-                                if (module)
+                                if (sc && sc->module_sp.get())
                                 {
+                                    Module *module = sc->module_sp.get();
                                     var_name_begin += ::strlen ("module.");
                                     
                                     if (::strncmp (var_name_begin, "file.", strlen("file.")) == 0)
@@ -1078,47 +1074,62 @@
                             // If format addr is valid, then we need to print an address
                             if (format_addr.IsValid())
                             {
+                                var_success = false;
+
                                 if (calculate_format_addr_function_offset)
                                 {
                                     Address func_addr;
-                                    if (sc->function)
-                                        func_addr = sc->function->GetAddressRange().GetBaseAddress();
-                                    else if (sc->symbol && sc->symbol->GetAddressRangePtr())
-                                        func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
-                                    else
-                                        var_success = false;
                                     
-                                    if (var_success)
+                                    if (sc)
+                                    {
+                                        if (sc->function)
+                                            func_addr = sc->function->GetAddressRange().GetBaseAddress();
+                                        else if (sc->symbol && sc->symbol->GetAddressRangePtr())
+                                            func_addr = sc->symbol->GetAddressRangePtr()->GetBaseAddress();
+                                    }
+                                    
+                                    if (func_addr.IsValid())
                                     {
                                         if (func_addr.GetSection() == format_addr.GetSection())
                                         {
                                             addr_t func_file_addr = func_addr.GetFileAddress();
                                             addr_t addr_file_addr = format_addr.GetFileAddress();
                                             if (addr_file_addr > func_file_addr)
-                                            {
                                                 s.Printf(" + %llu", addr_file_addr - func_file_addr);
-                                            }
                                             else if (addr_file_addr < func_file_addr)
-                                            {
                                                 s.Printf(" - %llu", func_file_addr - addr_file_addr);
-                                            }
+                                            var_success = true;
                                         }
                                         else
-                                            var_success = false;
+                                        {
+                                            Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
+                                            if (target)
+                                            {
+                                                addr_t func_load_addr = func_addr.GetLoadAddress (target);
+                                                addr_t addr_load_addr = format_addr.GetLoadAddress (target);
+                                                if (addr_load_addr > func_load_addr)
+                                                    s.Printf(" + %llu", addr_load_addr - func_load_addr);
+                                                else if (addr_load_addr < func_load_addr)
+                                                    s.Printf(" - %llu", func_load_addr - addr_load_addr);
+                                                var_success = true;
+                                            }
+                                        }
                                     }
                                 }
                                 else
                                 {
+                                    Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
                                     addr_t vaddr = LLDB_INVALID_ADDRESS;
-                                    if (exe_ctx && exe_ctx->process && !exe_ctx->process->GetTarget().GetSectionLoadList().IsEmpty())
-                                        vaddr = format_addr.GetLoadAddress (&exe_ctx->process->GetTarget());
+                                    if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
+                                        vaddr = format_addr.GetLoadAddress (target);
                                     if (vaddr == LLDB_INVALID_ADDRESS)
                                         vaddr = format_addr.GetFileAddress ();
 
                                     if (vaddr != LLDB_INVALID_ADDRESS)
+                                    {
                                         s.Printf("0x%16.16llx", vaddr);
-                                    else
-                                        var_success = false;
+                                        var_success = true;
+                                    }
                                 }
                             }
                         }
@@ -1154,47 +1165,57 @@
             case '0':
                 // 1 to 3 octal chars
                 {
-                    unsigned long octal_value = 0;
-                    ++p;
-                    int i=0;
-                    for (; i<3; ++i)
+                    // Make a string that can hold onto the initial zero char,
+                    // up to 3 octal digits, and a terminating NULL.
+                    char oct_str[5] = { 0, 0, 0, 0, 0 };
+
+                    int i;
+                    for (i=0; (p[i] >= '0' && p[i] <= '7') && i<4; ++i)
+                        oct_str[i] = p[i];
+
+                    // We don't want to consume the last octal character since
+                    // the main for loop will do this for us, so we advance p by
+                    // one less than i (even if i is zero)
+                    p += i - 1;
+                    unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
+                    if (octal_value <= UINT8_MAX)
                     {
-                        if (*p >= '0' && *p <= '7')
-                            octal_value = octal_value << 3 + (((uint8_t)*p) - '0');
-                        else
-                            break;
+                        char octal_char = octal_value;
+                        s.Write (&octal_char, 1);
                     }
-                    if (i>0)
-                        s.PutChar (octal_value);
-                    else
-                        s.PutCString ("\\0");
                 }
                 break;
 
             case 'x':
                 // hex number in the format 
+                if (isxdigit(p[1]))
                 {
-                    ++p;
+                    ++p;    // Skip the 'x'
 
-                    if (isxdigit(*p))
-                    {
-                        char hex_str[3] = { 0,0,0 };
-                        hex_str[0] = *p;
-                        ++p;
-                        if (isxdigit(*p))
-                            hex_str[1] = *p;
-                        unsigned long hex_value = strtoul (hex_str, NULL, 16);                    
-                        s.PutChar (hex_value);
-                    }
-                    else
+                    // Make a string that can hold onto two hex chars plus a
+                    // NULL terminator
+                    char hex_str[3] = { 0,0,0 };
+                    hex_str[0] = *p;
+                    if (isxdigit(p[1]))
                     {
-                        s.PutCString ("\\x");
+                        ++p; // Skip the first of the two hex chars
+                        hex_str[1] = *p;
                     }
+
+                    unsigned long hex_value = strtoul (hex_str, NULL, 16);                    
+                    if (hex_value <= UINT8_MAX)
+                        s.PutChar (hex_value);
+                }
+                else
+                {
+                    s.PutChar('x');
                 }
                 break;
                 
             default:
-                s << '\\' << *p;
+                // Just desensitize any other character by just printing what
+                // came after the '\'
+                s << *p;
                 break;
             
             }
@@ -1247,6 +1268,8 @@
     InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance),
     m_term_width (80),
     m_prompt (),
+    m_frame_format (),
+    m_thread_format (),    
     m_script_lang (),
     m_use_external_editor (false)
 {
@@ -1265,13 +1288,14 @@
     {
         const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
         CopyInstanceSettings (pending_settings, false);
-      //m_owner.RemovePendingSettings (m_instance_name);
     }
 }
 
 DebuggerInstanceSettings::DebuggerInstanceSettings (const DebuggerInstanceSettings &rhs) :
     InstanceSettings (*(Debugger::GetSettingsController().get()), CreateInstanceName ().AsCString()),
     m_prompt (rhs.m_prompt),
+    m_frame_format (rhs.m_frame_format),
+    m_thread_format (rhs.m_thread_format),
     m_script_lang (rhs.m_script_lang),
     m_use_external_editor (rhs.m_use_external_editor)
 {
@@ -1291,6 +1315,8 @@
     {
         m_term_width = rhs.m_term_width;
         m_prompt = rhs.m_prompt;
+        m_frame_format = rhs.m_frame_format;
+        m_thread_format = rhs.m_thread_format;
         m_script_lang = rhs.m_script_lang;
         m_use_external_editor = rhs.m_use_external_editor;
     }
@@ -1338,7 +1364,15 @@
                                                           Error &err,
                                                           bool pending)
 {
-    if (var_name == PromptVarName())
+
+    if (var_name == TermWidthVarName())
+    {
+        if (ValidTermWidthValue (value, err))
+        {
+            m_term_width = ::strtoul (value, NULL, 0);
+        }
+    }
+    else if (var_name == PromptVarName())
     {
         UserSettingsController::UpdateStringVariable (op, m_prompt, value, err);
         if (!pending)
@@ -1355,19 +1389,20 @@
             BroadcastPromptChange (new_name, m_prompt.c_str());
         }
     }
+    else if (var_name == GetFrameFormatName())
+    {
+        UserSettingsController::UpdateStringVariable (op, m_frame_format, value, err);
+    }
+    else if (var_name == GetThreadFormatName())
+    {
+        UserSettingsController::UpdateStringVariable (op, m_thread_format, value, err);
+    }
     else if (var_name == ScriptLangVarName())
     {
         bool success;
         m_script_lang = Args::StringToScriptLanguage (value, eScriptLanguageDefault,
                                                       &success);
     }
-    else if (var_name == TermWidthVarName())
-    {
-        if (ValidTermWidthValue (value, err))
-        {
-            m_term_width = ::strtoul (value, NULL, 0);
-        }
-    }
     else if (var_name == UseExternalEditorVarName ())
     {
         UserSettingsController::UpdateBooleanVariable (op, m_use_external_editor, value, err);
@@ -1382,7 +1417,7 @@
 {
     if (var_name == PromptVarName())
     {
-        value.AppendString (m_prompt.c_str());
+        value.AppendString (m_prompt.c_str(), m_prompt.size());
         
     }
     else if (var_name == ScriptLangVarName())
@@ -1395,6 +1430,14 @@
         width_str.Printf ("%d", m_term_width);
         value.AppendString (width_str.GetData());
     }
+    else if (var_name == GetFrameFormatName ())
+    {
+        value.AppendString(m_frame_format.c_str(), m_frame_format.size());
+    }
+    else if (var_name == GetThreadFormatName ())
+    {
+        value.AppendString(m_thread_format.c_str(), m_thread_format.size());
+    }
     else if (var_name == UseExternalEditorVarName())
     {
         if (m_use_external_editor)
@@ -1434,7 +1477,8 @@
 
         BroadcastPromptChange (new_name, m_prompt.c_str());
     }
-  
+    m_frame_format = new_debugger_settings->m_frame_format;
+    m_thread_format = new_debugger_settings->m_thread_format;
     m_term_width = new_debugger_settings->m_term_width;
     m_script_lang = new_debugger_settings->m_script_lang;
     m_use_external_editor = new_debugger_settings->m_use_external_editor;
@@ -1500,6 +1544,22 @@
 }
 
 const ConstString &
+DebuggerInstanceSettings::GetFrameFormatName ()
+{
+    static ConstString prompt_var_name ("frame-format");
+
+    return prompt_var_name;
+}
+
+const ConstString &
+DebuggerInstanceSettings::GetThreadFormatName ()
+{
+    static ConstString prompt_var_name ("thread-format");
+
+    return prompt_var_name;
+}
+
+const ConstString &
 DebuggerInstanceSettings::ScriptLangVarName ()
 {
     static ConstString script_lang_var_name ("script-lang");
@@ -1537,15 +1597,32 @@
     {  NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
 };
 
+#define MODULE_WITH_FUNC "{ ${module.file.basename}`${function.name}{${function.pc-offset}}}"
+#define FILE_AND_LINE "{ at ${line.file.basename}:${line.number}}"
 
+#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id}"\
+    "{, ${frame.pc}}"\
+    MODULE_WITH_FUNC\
+    "{, stop reason = ${thread.stop-reason}}"\
+    "{, name = ${thread.name}}"\
+    "{, queue = ${thread.queue}}"\
+    "\\n"
+
+#define DEFAULT_FRAME_FORMAT "frame #${frame.index}: ${frame.pc}"\
+    MODULE_WITH_FUNC\
+    FILE_AND_LINE\
+    "\\n"
 
 SettingEntry
 Debugger::SettingsController::instance_settings_table[] =
 {
-  //{ "var-name",     var-type ,        "default", enum-table, init'd, hidden, "help-text"},
-    { "term-width" , eSetVarTypeInt, "80"    , NULL,       false , false , "The maximum number of columns to use for displaying text." },
-    { "script-lang" , eSetVarTypeString, "python", NULL,       false,  false,  "The script language to be used for evaluating user-written scripts." },
-    { "prompt"      , eSetVarTypeString, "(lldb)", NULL,       false,  false,  "The debugger command line prompt displayed for the user." },
-    { "use-external-editor", eSetVarTypeBool, "false", NULL,   false,  false,  "Whether to use an external editor or not." },
-    {  NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
+//  NAME                    Setting variable type   Default                 Enum  Init'd Hidden Help
+//  ======================= ======================= ======================  ====  ====== ====== ======================
+{   "term-width",           eSetVarTypeInt,         "80"    ,               NULL, false, false, "The maximum number of columns to use for displaying text." },
+{   "script-lang",          eSetVarTypeString,      "python",               NULL, false, false, "The script language to be used for evaluating user-written scripts." },
+{   "prompt",               eSetVarTypeString,      "(lldb)",               NULL, false, false, "The debugger command line prompt displayed for the user." },
+{   "frame-format",         eSetVarTypeString,      DEFAULT_FRAME_FORMAT,   NULL, false, false, "The default frame format string to use when displaying thread information." },
+{   "thread-format",        eSetVarTypeString,      DEFAULT_THREAD_FORMAT,  NULL, false, false, "The default thread format string to use when displaying thread information." },
+{   "use-external-editor",  eSetVarTypeBool,        "false",                NULL, false, false, "Whether to use an external editor or not." },
+{   NULL,                   eSetVarTypeNone,        NULL,                   NULL, false, false, NULL }
 };

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCRuntimeV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCRuntimeV2.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCRuntimeV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCRuntimeV2.cpp Sun Oct  3 20:05:56 2010
@@ -66,7 +66,7 @@
         return false;
         
     ExecutionContext exe_ctx;
-    exe_scope->Calculate(exe_ctx);
+    exe_scope->CalculateExecutionContext(exe_ctx);
     
     if (!exe_ctx.process)
         return false;

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCTrampolineHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCTrampolineHandler.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCTrampolineHandler.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleObjCTrampolineHandler.cpp Sun Oct  3 20:05:56 2010
@@ -192,7 +192,7 @@
         // making the object value a load address value and resolving it will get
         // the pointer sized data pointed to by that value...
         ExecutionContext exec_ctx;
-        thread.Calculate (exec_ctx);
+        thread.CalculateExecutionContext (exec_ctx);
 
         isa_value.SetValueType(Value::eValueTypeLoadAddress);
         isa_value.ResolveValue(&exec_ctx, clang_ast_context->getASTContext());

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleThreadPlanStepThroughObjCTrampoline.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleThreadPlanStepThroughObjCTrampoline.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleThreadPlanStepThroughObjCTrampoline.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntimeV2/AppleThreadPlanStepThroughObjCTrampoline.cpp Sun Oct  3 20:05:56 2010
@@ -60,7 +60,7 @@
 {
     StreamString errors;
     ExecutionContext exc_context;
-    m_thread.Calculate(exc_context);
+    m_thread.CalculateExecutionContext(exc_context);
     m_func_sp.reset(m_impl_function->GetThreadPlanToCallFunction (exc_context, m_args_addr, errors, m_stop_others));
     m_func_sp->SetPrivate(true);
     m_thread.QueueThreadPlan (m_func_sp, false);
@@ -109,7 +109,7 @@
         {
             Value target_addr_value;
             ExecutionContext exc_context;
-            m_thread.Calculate(exc_context);
+            m_thread.CalculateExecutionContext(exc_context);
             m_impl_function->FetchFunctionResults (exc_context, m_args_addr, target_addr_value);
             m_impl_function->DeallocateFunctionResults(exc_context, m_args_addr);
             lldb::addr_t target_addr = target_addr_value.GetScalar().ULongLong();

Modified: lldb/trunk/source/Target/ExecutionContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ExecutionContext.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/ExecutionContext.cpp (original)
+++ lldb/trunk/source/Target/ExecutionContext.cpp Sun Oct  3 20:05:56 2010
@@ -59,7 +59,7 @@
 ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
 {
     if (exe_scope_ptr)
-        exe_scope_ptr->Calculate (*this);
+        exe_scope_ptr->CalculateExecutionContext (*this);
     else
     {
         target  = NULL;
@@ -71,7 +71,7 @@
 
 ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
 {
-    exe_scope_ref.Calculate (*this);
+    exe_scope_ref.CalculateExecutionContext (*this);
 }
 
 void

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Sun Oct  3 20:05:56 2010
@@ -1818,7 +1818,7 @@
 }
 
 void
-Process::Calculate (ExecutionContext &exe_ctx)
+Process::CalculateExecutionContext (ExecutionContext &exe_ctx)
 {
     exe_ctx.target = &m_target;
     exe_ctx.process = this;

Modified: lldb/trunk/source/Target/RegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/RegisterContext.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/RegisterContext.cpp (original)
+++ lldb/trunk/source/Target/RegisterContext.cpp Sun Oct  3 20:05:56 2010
@@ -226,12 +226,12 @@
 }
 
 void
-RegisterContext::Calculate (ExecutionContext &exe_ctx)
+RegisterContext::CalculateExecutionContext (ExecutionContext &exe_ctx)
 {
     if (m_frame)
-        m_frame->Calculate (exe_ctx);
+        m_frame->CalculateExecutionContext (exe_ctx);
     else
-        m_thread.Calculate (exe_ctx);
+        m_thread.CalculateExecutionContext (exe_ctx);
 }
 
 

Modified: lldb/trunk/source/Target/StackFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrame.cpp (original)
+++ lldb/trunk/source/Target/StackFrame.cpp Sun Oct  3 20:05:56 2010
@@ -14,6 +14,7 @@
 // Other libraries and framework includes
 // Project includes
 #include "lldb/Core/Module.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Disassembler.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/ValueObjectVariable.h"
@@ -248,7 +249,7 @@
     if (m_disassembly.GetSize() == 0)
     {
         ExecutionContext exe_ctx;
-        Calculate(exe_ctx);
+        CalculateExecutionContext(exe_ctx);
         Target &target = m_thread.GetProcess().GetTarget();
         Disassembler::Disassemble (target.GetDebugger(),
                                    target.GetArchitecture(),
@@ -615,13 +616,36 @@
 
 
 void
-StackFrame::Calculate (ExecutionContext &exe_ctx)
+StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx)
 {
-    m_thread.Calculate (exe_ctx);
+    m_thread.CalculateExecutionContext (exe_ctx);
     exe_ctx.frame = this;
 }
 
 void
+StackFrame::DumpUsingSettingsFormat (Stream *strm)
+{
+    if (strm == NULL)
+        return;
+
+    GetSymbolContext(eSymbolContextEverything);
+    ExecutionContext exe_ctx;
+    CalculateExecutionContext(exe_ctx);
+    const char *end = NULL;
+    StreamString s;
+    const char *frame_format = m_thread.GetProcess().GetTarget().GetDebugger().GetFrameFormat();
+    if (frame_format && Debugger::FormatPrompt (frame_format, &m_sc, &exe_ctx, NULL, s, &end))
+    {
+        strm->Write(s.GetData(), s.GetSize());
+    }
+    else
+    {
+        Dump (strm, true, false);
+        strm->EOL();
+    }
+}
+
+void
 StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
 {
     if (strm == NULL)

Modified: lldb/trunk/source/Target/StackFrameList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrameList.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/StackFrameList.cpp (original)
+++ lldb/trunk/source/Target/StackFrameList.cpp Sun Oct  3 20:05:56 2010
@@ -260,7 +260,7 @@
         if (frame)
         {
             frame->GetStackID().Dump (s);
-            frame->Dump(s, true, false);
+            frame->DumpUsingSettingsFormat (s);
         }
         else
             s->Printf("frame #%u", std::distance (begin, pos));

Modified: lldb/trunk/source/Target/StopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/StopInfo.cpp (original)
+++ lldb/trunk/source/Target/StopInfo.cpp Sun Oct  3 20:05:56 2010
@@ -276,9 +276,9 @@
             StreamString strm;
             const char *signal_name = m_thread.GetProcess().GetUnixSignals().GetSignalAsCString (m_value);
             if (signal_name)
-                strm.Printf("signal = %s", signal_name);
+                strm.Printf("signal %s", signal_name);
             else
-                strm.Printf("signal = %lli", m_value);
+                strm.Printf("signal %lli", m_value);
             m_description.swap (strm.GetString());
         }
         return m_description.c_str();

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Sun Oct  3 20:05:56 2010
@@ -708,7 +708,7 @@
 }
 
 void
-Target::Calculate (ExecutionContext &exe_ctx)
+Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
 {
     exe_ctx.target = this;
     exe_ctx.process = NULL; // Do NOT fill in process...
@@ -794,6 +794,25 @@
                                                        lldb::eVarSetOperationAssign, false, "[]");
 }
 
+Target *
+Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
+{
+    // The target can either exist in the "process" of ExecutionContext, or in 
+    // the "target_sp" member of SymbolContext. This accessor helper function
+    // will get the target from one of these locations.
+
+    Target *target = NULL;
+    if (sc_ptr != NULL)
+        target = sc_ptr->target_sp.get();
+    if (target == NULL)
+    {
+        if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL)
+            target = &exe_ctx_ptr->process->GetTarget();
+    }
+    return target;
+}
+
+
 void
 Target::UpdateInstanceName ()
 {

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=115485&r1=115484&r2=115485&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Sun Oct  3 20:05:56 2010
@@ -9,6 +9,7 @@
 
 #include "lldb/lldb-private-log.h"
 #include "lldb/Breakpoint/BreakpointLocation.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StreamString.h"
@@ -810,9 +811,9 @@
 }
 
 void
-Thread::Calculate (ExecutionContext &exe_ctx)
+Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
 {
-    m_process.Calculate (exe_ctx);
+    m_process.CalculateExecutionContext (exe_ctx);
     exe_ctx.thread = this;
     exe_ctx.frame = NULL;
 }
@@ -872,52 +873,31 @@
 }
 
 void
-Thread::DumpInfo
-(
-    Stream &strm,
-    bool show_stop_reason,
-    bool show_name,
-    bool show_queue,
-    uint32_t idx
-)
+Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
 {
-    strm.Printf("thread #%u: tid = 0x%4.4x", GetIndexID(), GetID());
+    ExecutionContext exe_ctx;
+    SymbolContext frame_sc;
+    CalculateExecutionContext (exe_ctx);
 
-    if (idx != LLDB_INVALID_INDEX32)
+    if (frame_idx != LLDB_INVALID_INDEX32)
     {
-        StackFrameSP frame_sp(GetStackFrameAtIndex (idx));
+        StackFrameSP frame_sp(GetStackFrameAtIndex (frame_idx));
         if (frame_sp)
         {
-            strm.PutCString(", ");
-            frame_sp->Dump (&strm, false, false);
+            exe_ctx.frame = frame_sp.get();
+            frame_sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
         }
     }
 
-    if (show_stop_reason)
-    {
-        StopInfo *stop_info = GetStopInfo();
-        
-        if (stop_info)
-        {
-            const char *stop_description = stop_info->GetDescription();
-            if (stop_description)
-                strm.Printf (", stop reason = %s", stop_description);
-        }
-    }
-
-    if (show_name)
-    {
-        const char *name = GetName();
-        if (name && name[0])
-            strm.Printf(", name = %s", name);
-    }
-
-    if (show_queue)
-    {
-        const char *queue = GetQueueName();
-        if (queue && queue[0])
-            strm.Printf(", queue = %s", queue);
-    }
+    const char *thread_format = GetProcess().GetTarget().GetDebugger().GetThreadFormat();
+    assert (thread_format);
+    const char *end = NULL;
+    Debugger::FormatPrompt (thread_format, 
+                            exe_ctx.frame ? &frame_sc : NULL,
+                            &exe_ctx, 
+                            NULL,
+                            strm, 
+                            &end);
 }
 
 lldb::ThreadSP





More information about the lldb-commits mailing list