[Lldb-commits] [lldb] r148110 - /lldb/trunk/source/Core/Debugger.cpp

Greg Clayton gclayton at apple.com
Fri Jan 13 00:39:16 PST 2012


Author: gclayton
Date: Fri Jan 13 02:39:16 2012
New Revision: 148110

URL: http://llvm.org/viewvc/llvm-project?rev=148110&view=rev
Log:
Added a new thread and frame format that can be used to display a function
name + arguments when the data is available. It seems to work really well, 
but some more testing is needed before we make this on by default.

The new function format name is:

 ${function.name-with-args}

To see how to use these formats see the website:

    http://lldb.llvm.org/formats.html

Here is a sample backtrace of debugging LLDB with LLDB using this new format
value:

(lldb) thread backtrace all
* thread #1: tid = 0x2203, 0x00007fff88a17bca libsystem_kernel.dylib __psynch_cvwait + 10, stop reason = signal SIGINT, name = <lldb.driver.main-thread>, queue = com.apple.main-thread
    frame #0: 0x00007fff88a17bca libsystem_kernel.dylib __psynch_cvwait + 10
    frame #1: 0x00007fff884ae274 libsystem_c.dylib _pthread_cond_wait + 840
    frame #2: 0x00000001010778ea LLDB lldb_private::Condition::Wait(this=0x0000000104846770, mutex=0x0000000104846730, abstime=0x0000000000000000, timed_out=0x00007fff5fbfdea7) + 138 at Condition.cpp:92
    frame #3: 0x0000000101244c21 LLDB lldb_private::Predicate<bool>::WaitForValueEqualTo(this=0x0000000104846728, value=true, abstime=0x0000000000000000, timed_out=0x00007fff5fbfdea7) + 209 at Predicate.h:317
    frame #4: 0x0000000100f6eeb2 LLDB lldb_private::Listener::WaitForEventsInternal(this=0x0000000104846660, timeout=0x0000000000000000, broadcaster=0x0000000000000000, broadcaster_names=0x0000000000000000, num_broadcaster_names=0x00000000, event_type_mask=0x00000000, event_sp=0x00007fff5fbfe030) + 386 at Listener.cpp:388
    frame #5: 0x0000000100f6f231 LLDB lldb_private::Listener::WaitForEvent(this=0x0000000104846660, timeout=0x0000000000000000, event_sp=0x00007fff5fbfe030) + 81 at Listener.cpp:436
    frame #6: 0x0000000100098dcd LLDB lldb::SBListener::WaitForEvent(this=0x00007fff5fbff0f0, timeout_secs=0xffffffff, event=0x00007fff5fbfe430) + 685 at SBListener.cpp:181
    frame #7: 0x000000010000628c lldb Driver::MainLoop(this=0x00007fff5fbff620) + 5244 at Driver.cpp:1325
    frame #8: 0x0000000100006ca3 lldb main(argc=1, argv=0x00007fff5fbff758, envp=0x00007fff5fbff768) + 419 at Driver.cpp:1460
    frame #9: 0x0000000100000d54 lldb start + 52

  thread #3: tid = 0x2703, 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10, name = <lldb.comm.debugger.input>
    frame #0: 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10
    frame #1: 0x0000000100f3f072 LLDB lldb_private::ConnectionFileDescriptor::BytesAvailable(this=0x000000010524d040, timeout_usec=0x004c4b40, error_ptr=0x0000000105640a18) + 722 at ConnectionFileDescriptor.cpp:542
    frame #2: 0x0000000100f3e6dd LLDB lldb_private::ConnectionFileDescriptor::Read(this=0x000000010524d040, dst=0x0000000105640a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x0000000105640a14, error_ptr=0x0000000105640a18) + 301 at ConnectionFileDescriptor.cpp:273
    frame #3: 0x0000000100f3b8f7 LLDB lldb_private::Communication::ReadFromConnection(this=0x0000000104846270, dst=0x0000000105640a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x0000000105640a14, error_ptr=0x0000000105640a18) + 167 at Communication.cpp:317
    frame #4: 0x0000000100f3b197 LLDB lldb_private::Communication::ReadThread(p=0x0000000104846270) + 327 at Communication.cpp:344
    frame #5: 0x0000000101078923 LLDB ThreadCreateTrampoline(arg=0x00000001045f6650) + 227 at Host.cpp:549
    frame #6: 0x00007fff884aa8bf libsystem_c.dylib _pthread_start + 335
    frame #7: 0x00007fff884adb75 libsystem_c.dylib thread_start + 13

  thread #4: tid = 0x2803, 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10, name = <lldb.comm.driver.editline>
    frame #0: 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10
    frame #1: 0x0000000100f3f072 LLDB lldb_private::ConnectionFileDescriptor::BytesAvailable(this=0x0000000105700370, timeout_usec=0x004c4b40, error_ptr=0x00000001056c3a18) + 722 at ConnectionFileDescriptor.cpp:542
    frame #2: 0x0000000100f3e6dd LLDB lldb_private::ConnectionFileDescriptor::Read(this=0x0000000105700370, dst=0x00000001056c3a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x00000001056c3a14, error_ptr=0x00000001056c3a18) + 301 at ConnectionFileDescriptor.cpp:273
    frame #3: 0x0000000100f3b8f7 LLDB lldb_private::Communication::ReadFromConnection(this=0x0000000105700000, dst=0x00000001056c3a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x00000001056c3a14, error_ptr=0x00000001056c3a18) + 167 at Communication.cpp:317
    frame #4: 0x0000000100f3b197 LLDB lldb_private::Communication::ReadThread(p=0x0000000105700000) + 327 at Communication.cpp:344
    frame #5: 0x0000000101078923 LLDB ThreadCreateTrampoline(arg=0x0000000105700430) + 227 at Host.cpp:549
    frame #6: 0x00007fff884aa8bf libsystem_c.dylib _pthread_start + 335
    frame #7: 0x00007fff884adb75 libsystem_c.dylib thread_start + 13

  thread #5: tid = 0x2903, 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10, name = <lldb.comm.driver.editline_output>
    frame #0: 0x00007fff88a17df2 libsystem_kernel.dylib select$DARWIN_EXTSN + 10
    frame #1: 0x0000000100f3f072 LLDB lldb_private::ConnectionFileDescriptor::BytesAvailable(this=0x00000001057178f0, timeout_usec=0x004c4b40, error_ptr=0x0000000105980a18) + 722 at ConnectionFileDescriptor.cpp:542
    frame #2: 0x0000000100f3e6dd LLDB lldb_private::ConnectionFileDescriptor::Read(this=0x00000001057178f0, dst=0x0000000105980a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x0000000105980a14, error_ptr=0x0000000105980a18) + 301 at ConnectionFileDescriptor.cpp:273
    frame #3: 0x0000000100f3b8f7 LLDB lldb_private::Communication::ReadFromConnection(this=0x0000000105717580, dst=0x0000000105980a60, dst_len=1024, timeout_usec=0x004c4b40, status=0x0000000105980a14, error_ptr=0x0000000105980a18) + 167 at Communication.cpp:317
    frame #4: 0x0000000100f3b197 LLDB lldb_private::Communication::ReadThread(p=0x0000000105717580) + 327 at Communication.cpp:344
    frame #5: 0x0000000101078923 LLDB ThreadCreateTrampoline(arg=0x00000001057179b0) + 227 at Host.cpp:549
    frame #6: 0x00007fff884aa8bf libsystem_c.dylib _pthread_start + 335
    frame #7: 0x00007fff884adb75 libsystem_c.dylib thread_start + 13

  thread #6: tid = 0x2a03, 0x00007fff88a18af2 libsystem_kernel.dylib read + 10, name = <lldb.driver.commandline_io>
    frame #0: 0x00007fff88a18af2 libsystem_kernel.dylib read + 10
    frame #1: 0x0000000100050c3b libedit.3.dylib read_init + 247
    frame #2: 0x0000000100050e96 libedit.3.dylib el_wgetc + 155
    frame #3: 0x000000010005115d libedit.3.dylib el_wgets + 578
    frame #4: 0x000000010005debc libedit.3.dylib el_gets + 37
    frame #5: 0x000000010000d409 lldb IOChannel::LibeditGetInput(this=0x0000000105700490, new_line=0x0000000105a03db0) + 89 at IOChannel.cpp:311
    frame #6: 0x000000010000d8b6 lldb IOChannel::Run(this=0x0000000105700490) + 806 at IOChannel.cpp:391
    frame #7: 0x000000010000d57d lldb IOChannel::IOReadThread(ptr=0x0000000105700490) + 29 at IOChannel.cpp:345
    frame #8: 0x0000000101078923 LLDB ThreadCreateTrampoline(arg=0x00000001057179f0) + 227 at Host.cpp:549
    frame #9: 0x00007fff884aa8bf libsystem_c.dylib _pthread_start + 335
    frame #10: 0x00007fff884adb75 libsystem_c.dylib thread_start + 13
(lldb) 



Modified:
    lldb/trunk/source/Core/Debugger.cpp

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=148110&r1=148109&r2=148110&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Fri Jan 13 02:39:16 2012
@@ -24,8 +24,10 @@
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/ValueObject.h"
+#include "lldb/Core/ValueObjectVariable.h"
 #include "lldb/Host/Terminal.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Symbol/VariableList.h"
 #include "lldb/Target/TargetList.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/RegisterContext.h"
@@ -1883,6 +1885,108 @@
                                             var_success = true;
                                         }
                                     }
+                                    else if (::strncmp (var_name_begin, "name-with-args}", strlen("name-with-args}")) == 0)
+                                    {
+                                        // Print the function name with arguments in it
+
+                                        if (sc->function)
+                                        {
+                                            var_success = true;
+                                            ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
+                                            cstr = sc->function->GetName().AsCString (NULL);
+                                            if (cstr)
+                                            {
+                                                const InlineFunctionInfo *inline_info = NULL;
+                                                VariableListSP variable_list_sp;
+                                                bool get_function_vars = true;
+                                                if (sc->block)
+                                                {
+                                                    Block *inline_block = sc->block->GetContainingInlinedBlock ();
+
+                                                    if (inline_block)
+                                                    {
+                                                        get_function_vars = false;
+                                                        inline_info = sc->block->GetInlinedFunctionInfo();
+                                                        if (inline_info)
+                                                            variable_list_sp = inline_block->GetBlockVariableList (true);
+                                                    }
+                                                }
+                                                
+                                                if (get_function_vars)
+                                                {
+                                                    variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
+                                                }
+                                                
+                                                if (inline_info)
+                                                {
+                                                    s.PutCString (cstr);
+                                                    s.PutCString (" [inlined] ");
+                                                    cstr = inline_info->GetName().GetCString();
+                                                }
+                                                
+                                                VariableList args;
+                                                if (variable_list_sp)
+                                                {
+                                                    const size_t num_variables = variable_list_sp->GetSize();
+                                                    for (size_t var_idx = 0; var_idx < num_variables; ++var_idx)
+                                                    {
+                                                        VariableSP var_sp (variable_list_sp->GetVariableAtIndex(var_idx));
+                                                        if (var_sp->GetScope() == eValueTypeVariableArgument)
+                                                            args.AddVariable (var_sp);
+                                                    }
+
+                                                }
+                                                if (args.GetSize() > 0)
+                                                {
+                                                    const char *open_paren = strchr (cstr, '(');
+                                                    const char *close_paren = NULL;
+                                                    if (open_paren)
+                                                        close_paren = strchr (open_paren, ')');
+                                                    
+                                                    if (open_paren)
+                                                        s.Write(cstr, open_paren - cstr + 1);
+                                                    else
+                                                    {
+                                                        s.PutCString (cstr);
+                                                        s.PutChar ('(');
+                                                    }
+                                                    const size_t num_args = variable_list_sp->GetSize();
+                                                    for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
+                                                    {
+                                                        VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
+                                                        ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
+                                                        const char *var_name = var_value_sp->GetName().GetCString();
+                                                        const char *var_value = var_value_sp->GetValueAsCString();
+                                                        if (var_value_sp->GetError().Success())
+                                                        {
+                                                            if (arg_idx > 0)
+                                                                s.PutCString (", ");
+                                                            s.Printf ("%s=%s", var_name, var_value);
+                                                        }
+                                                    }
+                                                    
+                                                    if (close_paren)
+                                                        s.PutCString (close_paren);
+                                                    else
+                                                        s.PutChar(')');
+
+                                                }
+                                                else
+                                                {
+                                                    s.PutCString(cstr);
+                                                }
+                                            }
+                                        }
+                                        else if (sc->symbol)
+                                        {
+                                            cstr = sc->symbol->GetName().AsCString (NULL);
+                                            if (cstr)
+                                            {
+                                                s.PutCString(cstr);
+                                                var_success = true;
+                                            }
+                                        }
+                                    }
                                     else if (::strncmp (var_name_begin, "addr-offset}", strlen("addr-offset}")) == 0)
                                     {
                                         var_success = addr != NULL;





More information about the lldb-commits mailing list