Add support for displaying the language in the frame-format string.
authorDawn Perchik <dawn@burble.org>
Tue, 23 Jun 2015 18:35:31 +0000 (18:35 +0000)
committerDawn Perchik <dawn@burble.org>
Tue, 23 Jun 2015 18:35:31 +0000 (18:35 +0000)
Enable ${language} to be specified in the frame-format string to see
the current frame's compile unit language in "frame info".

Test Plan:
debug a C++ program, run to main, and run the lldb commands:
    settings set frame-format "frame lang=${language}\n"
    frame info
you should see:
    frame lang=c++
test case added in:
    ./dotest.py --executable lldb -f SettingsCommandTestCase.test_set_frame_format
Reviewers: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D10561

llvm-svn: 240440

lldb/include/lldb/Core/FormatEntity.h
lldb/source/Core/FormatEntity.cpp
lldb/test/settings/TestSettings.py
lldb/www/formats.html

index 4ae4fd38dbb76c3c4119965c513e4e7bd2ac5588..db4f59132832e0f0cc0a585ac6d3178b814f19de 100644 (file)
@@ -61,6 +61,7 @@ namespace lldb_private
                 ScriptTarget,
                 ModuleFile,
                 File,
+                Lang,
                 FrameIndex,
                 FrameRegisterPC,
                 FrameRegisterSP,
index b1f28ae17c3f8e337e4d5bb4dd77b58e74d85385..1dec0bfb97e31c6689bb6aca3d3835c092fe98f3 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "lldb/Core/Address.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/Language.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StreamString.h"
@@ -210,6 +211,7 @@ static FormatEntity::Entry::Definition g_top_level_entries[] =
     ENTRY_CHILDREN          ("ansi"                , Invalid                , None      , g_ansi_entries),
     ENTRY                   ("current-pc-arrow"    , CurrentPCArrow         , CString   ),
     ENTRY_CHILDREN          ("file"                , File                   , CString   , g_file_child_entries),
+    ENTRY                   ("language"            , Lang                   , CString),
     ENTRY_CHILDREN          ("frame"               , Invalid                , None      , g_frame_child_entries),
     ENTRY_CHILDREN          ("function"            , Invalid                , None      , g_function_child_entries),
     ENTRY_CHILDREN          ("line"                , Invalid                , None      , g_line_child_entries),
@@ -321,6 +323,7 @@ FormatEntity::Entry::TypeToCString (Type t)
     ENUM_TO_CSTR(ScriptTarget);
     ENUM_TO_CSTR(ModuleFile);
     ENUM_TO_CSTR(File);
+    ENUM_TO_CSTR(Lang);
     ENUM_TO_CSTR(FrameIndex);
     ENUM_TO_CSTR(FrameRegisterPC);
     ENUM_TO_CSTR(FrameRegisterSP);
@@ -1515,6 +1518,23 @@ FormatEntity::Format (const Entry &entry,
             }
             return false;
 
+        case Entry::Type::Lang:
+            if (sc)
+            {
+                CompileUnit *cu = sc->comp_unit;
+                if (cu)
+                {
+                    Language lang(cu->GetLanguage());
+                    const char *lang_name = lang.AsCString();
+                    if (lang_name)
+                    {
+                        s.PutCString(lang_name);
+                        return true;
+                    }
+                }
+            }
+            return false;
+
         case Entry::Type::FrameIndex:
             if (exe_ctx)
             {
index 4305107936c264a2c941b56a60a8950fb7522cf5..17d34b73f6a984a608ab51e4b9126509908d1c64 100644 (file)
@@ -129,7 +129,7 @@ class SettingsCommandTestCase(TestBase):
         self.format_string = m.group(1)
 
         # Change the default format to print function.name rather than function.name-with-args
-        format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
+        format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n"
         self.runCmd("settings set frame-format %s" % format_string)
 
         # Immediately test the setting.
index cbc32ad0052b70d96e3a015e26e4580f91b09626..58db831d596fd2880859bb62516f1941ab68e74e 100755 (executable)
@@ -73,6 +73,7 @@
                     <tr valign=top><td><b>Variable Name</b></td><td><b>Description</b></td></tr>
                     <tr valign=top><td><b>file.basename</b></td><td>The current compile unit file basename for the current frame.</td></tr>
                     <tr valign=top><td><b>file.fullpath</b></td><td>The current compile unit file fullpath for the current frame.</td></tr>
+                    <tr valign=top><td><b>language</b></td><td>The current compile unit language for the current frame.</td></tr>
                     <tr valign=top><td><b>frame.index</b></td><td>The frame index (0, 1, 2, 3...)</td></tr>
                     <tr valign=top><td><b>frame.pc</b></td><td>The generic frame register for the program counter.</td></tr>
                     <tr valign=top><td><b>frame.sp</b></td><td>The generic frame register for the stack pointer.</td></tr>