|
23 | 23 | #include "lldb/Core/Module.h"
|
24 | 24 | #include "lldb/Core/PluginManager.h"
|
25 | 25 | #include "lldb/Core/UniqueCStringMap.h"
|
| 26 | +#include "lldb/Core/ValueObjectVariable.h" |
26 | 27 | #include "lldb/DataFormatters/CXXFunctionPointer.h"
|
27 | 28 | #include "lldb/DataFormatters/DataVisualization.h"
|
28 | 29 | #include "lldb/DataFormatters/FormattersHelpers.h"
|
29 | 30 | #include "lldb/DataFormatters/VectorType.h"
|
30 | 31 | #include "lldb/Symbol/SymbolFile.h"
|
| 32 | +#include "lldb/Symbol/VariableList.h" |
31 | 33 | #include "lldb/Utility/ConstString.h"
|
32 | 34 | #include "lldb/Utility/LLDBLog.h"
|
33 | 35 | #include "lldb/Utility/Log.h"
|
@@ -171,6 +173,40 @@ static bool IsTrivialBasename(const llvm::StringRef &basename) {
|
171 | 173 | return idx == basename.size();
|
172 | 174 | }
|
173 | 175 |
|
| 176 | +/// Writes out the function name in 'full_name' to 'out_stream' |
| 177 | +/// but replaces each argument type with the variable name |
| 178 | +/// and the corresponding pretty-printed value |
| 179 | +static bool PrettyPrintFunctionNameWithArgs(Stream &out_stream, |
| 180 | + char const *full_name, |
| 181 | + ExecutionContextScope *exe_scope, |
| 182 | + VariableList const &args) { |
| 183 | + CPlusPlusLanguage::MethodName cpp_method{ConstString(full_name)}; |
| 184 | + |
| 185 | + if (!cpp_method.IsValid()) |
| 186 | + return false; |
| 187 | + |
| 188 | + llvm::StringRef return_type = cpp_method.GetReturnType(); |
| 189 | + if (!return_type.empty()) { |
| 190 | + out_stream.PutCString(return_type); |
| 191 | + out_stream.PutChar(' '); |
| 192 | + } |
| 193 | + |
| 194 | + out_stream.PutCString(cpp_method.GetScopeQualifiedName()); |
| 195 | + out_stream.PutChar('('); |
| 196 | + |
| 197 | + FormatEntity::PrettyPrintFunctionArguments(out_stream, args, exe_scope); |
| 198 | + |
| 199 | + out_stream.PutChar(')'); |
| 200 | + |
| 201 | + llvm::StringRef qualifiers = cpp_method.GetQualifiers(); |
| 202 | + if (!qualifiers.empty()) { |
| 203 | + out_stream.PutChar(' '); |
| 204 | + out_stream.PutCString(qualifiers); |
| 205 | + } |
| 206 | + |
| 207 | + return true; |
| 208 | +} |
| 209 | + |
174 | 210 | bool CPlusPlusLanguage::MethodName::TrySimplifiedParse() {
|
175 | 211 | // This method tries to parse simple method definitions which are presumably
|
176 | 212 | // most comman in user programs. Definitions that can be parsed by this
|
@@ -1470,3 +1506,66 @@ bool CPlusPlusLanguage::IsSourceFile(llvm::StringRef file_path) const {
|
1470 | 1506 | // that we could check for.
|
1471 | 1507 | return file_path.contains("/usr/include/c++/");
|
1472 | 1508 | }
|
| 1509 | + |
| 1510 | +bool CPlusPlusLanguage::GetFunctionDisplayName( |
| 1511 | + const SymbolContext *sc, const ExecutionContext *exe_ctx, |
| 1512 | + FunctionNameRepresentation representation, Stream &s) { |
| 1513 | + switch (representation) { |
| 1514 | + case FunctionNameRepresentation::eNameWithArgs: { |
| 1515 | + // Print the function name with arguments in it |
| 1516 | + if (sc->function) { |
| 1517 | + ExecutionContextScope *exe_scope = |
| 1518 | + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr; |
| 1519 | + const char *cstr = sc->function->GetName().AsCString(nullptr); |
| 1520 | + if (cstr) { |
| 1521 | + const InlineFunctionInfo *inline_info = nullptr; |
| 1522 | + VariableListSP variable_list_sp; |
| 1523 | + bool get_function_vars = true; |
| 1524 | + if (sc->block) { |
| 1525 | + Block *inline_block = sc->block->GetContainingInlinedBlock(); |
| 1526 | + |
| 1527 | + if (inline_block) { |
| 1528 | + get_function_vars = false; |
| 1529 | + inline_info = sc->block->GetInlinedFunctionInfo(); |
| 1530 | + if (inline_info) |
| 1531 | + variable_list_sp = inline_block->GetBlockVariableList(true); |
| 1532 | + } |
| 1533 | + } |
| 1534 | + |
| 1535 | + if (get_function_vars) { |
| 1536 | + variable_list_sp = |
| 1537 | + sc->function->GetBlock(true).GetBlockVariableList(true); |
| 1538 | + } |
| 1539 | + |
| 1540 | + if (inline_info) { |
| 1541 | + s.PutCString(cstr); |
| 1542 | + s.PutCString(" [inlined] "); |
| 1543 | + cstr = inline_info->GetName().GetCString(); |
| 1544 | + } |
| 1545 | + |
| 1546 | + VariableList args; |
| 1547 | + if (variable_list_sp) |
| 1548 | + variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, |
| 1549 | + args); |
| 1550 | + if (args.GetSize() > 0) { |
| 1551 | + if (!PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args)) |
| 1552 | + return false; |
| 1553 | + } else { |
| 1554 | + s.PutCString(cstr); |
| 1555 | + } |
| 1556 | + return true; |
| 1557 | + } |
| 1558 | + } else if (sc->symbol) { |
| 1559 | + const char *cstr = sc->symbol->GetName().AsCString(nullptr); |
| 1560 | + if (cstr) { |
| 1561 | + s.PutCString(cstr); |
| 1562 | + return true; |
| 1563 | + } |
| 1564 | + } |
| 1565 | + } break; |
| 1566 | + default: |
| 1567 | + return false; |
| 1568 | + } |
| 1569 | + |
| 1570 | + return false; |
| 1571 | +} |
0 commit comments