Skip to content

Commit 06c54bc

Browse files
authored
[lldb] Implement ${target.file} format variable (llvm#123431)
Implements a format variable to print the basename and full path to the current target.
1 parent 3f0ac46 commit 06c54bc

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

lldb/docs/use/formatting.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ A complete list of currently supported format string variables is listed below:
113113
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
114114
| ``module.file.basename`` | The basename of the current module (shared library or executable) |
115115
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
116-
| ``module.file.fullpath`` | The basename of the current module (shared library or executable) |
116+
| ``module.file.fullpath`` | The path of the current module (shared library or executable) |
117117
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
118118
| ``process.file.basename`` | The basename of the file for the process |
119119
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
120-
| ``process.file.fullpath`` | The fullname of the file for the process |
120+
| ``process.file.fullpath`` | The path of the file for the process |
121121
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
122122
| ``process.id`` | The process ID native to the system on which the inferior runs. |
123123
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -141,6 +141,10 @@ A complete list of currently supported format string variables is listed below:
141141
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
142142
| ``target.arch`` | The architecture of the current target |
143143
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
144+
| ``target.file.basename`` | The basename of the current target |
145+
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
146+
| ``target.file.fullpath`` | The path of the current target |
147+
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
144148
| ``script.target:python_func`` | Use a Python function to generate a piece of textual output |
145149
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
146150
| ``script.process:python_func`` | Use a Python function to generate a piece of textual output |

lldb/include/lldb/Core/FormatEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct Entry {
6767
ScriptThread,
6868
ThreadInfo,
6969
TargetArch,
70+
TargetFile,
7071
ScriptTarget,
7172
ModuleFile,
7273
File,

lldb/source/Core/FormatEntity.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ constexpr Definition g_thread_child_entries[] = {
162162
Definition("completed-expression", EntryType::ThreadCompletedExpression)};
163163

164164
constexpr Definition g_target_child_entries[] = {
165-
Definition("arch", EntryType::TargetArch)};
165+
Definition("arch", EntryType::TargetArch),
166+
Entry::DefinitionWithChildren("file", EntryType::TargetFile,
167+
g_file_child_entries)};
166168

167169
#define _TO_STR2(_val) #_val
168170
#define _TO_STR(_val) _TO_STR2(_val)
@@ -322,6 +324,7 @@ const char *FormatEntity::Entry::TypeToCString(Type t) {
322324
ENUM_TO_CSTR(ScriptThread);
323325
ENUM_TO_CSTR(ThreadInfo);
324326
ENUM_TO_CSTR(TargetArch);
327+
ENUM_TO_CSTR(TargetFile);
325328
ENUM_TO_CSTR(ScriptTarget);
326329
ENUM_TO_CSTR(ModuleFile);
327330
ENUM_TO_CSTR(File);
@@ -1469,6 +1472,17 @@ bool FormatEntity::Format(const Entry &entry, Stream &s,
14691472
}
14701473
return false;
14711474

1475+
case Entry::Type::TargetFile:
1476+
if (exe_ctx) {
1477+
if (Target *target = exe_ctx->GetTargetPtr()) {
1478+
if (Module *exe_module = target->GetExecutableModulePointer()) {
1479+
if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1480+
return true;
1481+
}
1482+
}
1483+
}
1484+
return false;
1485+
14721486
case Entry::Type::ScriptTarget:
14731487
if (exe_ctx) {
14741488
Target *target = exe_ctx->GetTargetPtr();

lldb/unittests/Core/FormatEntityTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ constexpr llvm::StringRef lookupStrings[] = {
148148
"${thread.return-value}",
149149
"${thread.completed-expression}",
150150
"${target.arch}",
151+
"${target.file.basename}",
152+
"${target.file.dirname}",
153+
"${target.file.fullpath}",
151154
"${var.dummy-var-to-test-wildcard}"};
152155

153156
TEST(FormatEntity, LookupAllEntriesInTree) {

0 commit comments

Comments
 (0)