1 //===-- FormatEntity.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/FormatEntity.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/StringRef.h"
15 #include "lldb/Core/Address.h"
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/Module.h"
18 #include "lldb/Core/Stream.h"
19 #include "lldb/Core/StreamString.h"
20 #include "lldb/Core/ValueObject.h"
21 #include "lldb/Core/ValueObjectVariable.h"
22 #include "lldb/DataFormatters/DataVisualization.h"
23 #include "lldb/DataFormatters/FormatManager.h"
24 #include "lldb/DataFormatters/ValueObjectPrinter.h"
25 #include "lldb/Expression/ExpressionVariable.h"
26 #include "lldb/Host/FileSpec.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Symbol/Block.h"
29 #include "lldb/Symbol/CompileUnit.h"
30 #include "lldb/Symbol/Function.h"
31 #include "lldb/Symbol/LineEntry.h"
32 #include "lldb/Symbol/Symbol.h"
33 #include "lldb/Symbol/VariableList.h"
34 #include "lldb/Target/ExecutionContext.h"
35 #include "lldb/Target/Language.h"
36 #include "lldb/Target/Process.h"
37 #include "lldb/Target/RegisterContext.h"
38 #include "lldb/Target/SectionLoadList.h"
39 #include "lldb/Target/StackFrame.h"
40 #include "lldb/Target/StopInfo.h"
41 #include "lldb/Target/Target.h"
42 #include "lldb/Target/Thread.h"
43 #include "lldb/Utility/AnsiTerminal.h"
46 using namespace lldb_private;
57 #define ENTRY(n,t,f) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,0,NULL, false}
58 #define ENTRY_VALUE(n,t,f,v) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, v,0,NULL, false}
59 #define ENTRY_CHILDREN(n,t,f,c) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,llvm::array_lengthof(c),c, false}
60 #define ENTRY_CHILDREN_KEEP_SEP(n,t,f,c) { n, NULL, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0,llvm::array_lengthof(c),c, true}
61 #define ENTRY_STRING(n,s) { n, s, FormatEntity::Entry::Type::InsertString, FormatEntity::Entry::FormatType::None, 0,0, NULL, false}
62 static FormatEntity::Entry::Definition g_string_entry[] =
64 ENTRY("*", ParentString, None)
67 static FormatEntity::Entry::Definition g_addr_entries[] =
69 ENTRY ("load", AddressLoad , UInt64),
70 ENTRY ("file", AddressFile , UInt64),
71 ENTRY ("load", AddressLoadOrFile, UInt64),
74 static FormatEntity::Entry::Definition g_file_child_entries[] =
76 ENTRY_VALUE("basename", ParentNumber, CString, FileKind::Basename),
77 ENTRY_VALUE("dirname", ParentNumber, CString, FileKind::Dirname),
78 ENTRY_VALUE("fullpath", ParentNumber, CString, FileKind::Fullpath)
81 static FormatEntity::Entry::Definition g_frame_child_entries[] =
84 ENTRY ("index", FrameIndex , UInt32),
85 ENTRY ("pc" , FrameRegisterPC , UInt64),
86 ENTRY ("fp" , FrameRegisterFP , UInt64),
87 ENTRY ("sp" , FrameRegisterSP , UInt64),
88 ENTRY ("flags", FrameRegisterFlags, UInt64),
89 ENTRY_CHILDREN ("reg", FrameRegisterByName, UInt64, g_string_entry),
92 static FormatEntity::Entry::Definition g_function_child_entries[] =
94 ENTRY ("id" , FunctionID , UInt64),
95 ENTRY ("name" , FunctionName , CString),
96 ENTRY ("name-without-args" , FunctionNameNoArgs , CString),
97 ENTRY ("name-with-args" , FunctionNameWithArgs , CString),
98 ENTRY ("addr-offset" , FunctionAddrOffset , UInt64),
99 ENTRY ("concrete-only-addr-offset-no-padding", FunctionAddrOffsetConcrete, UInt64),
100 ENTRY ("line-offset" , FunctionLineOffset , UInt64),
101 ENTRY ("pc-offset" , FunctionPCOffset , UInt64),
102 ENTRY ("initial-function" , FunctionInitial , None),
103 ENTRY ("changed" , FunctionChanged , None),
104 ENTRY ("is-optimized" , FunctionIsOptimized , None)
107 static FormatEntity::Entry::Definition g_line_child_entries[] =
109 ENTRY_CHILDREN("file", LineEntryFile , None , g_file_child_entries),
110 ENTRY("number" , LineEntryLineNumber , UInt32),
111 ENTRY("start-addr" , LineEntryStartAddress, UInt64),
112 ENTRY("end-addr" , LineEntryEndAddress , UInt64),
115 static FormatEntity::Entry::Definition g_module_child_entries[] =
117 ENTRY_CHILDREN("file", ModuleFile, None, g_file_child_entries),
120 static FormatEntity::Entry::Definition g_process_child_entries[] =
122 ENTRY ( "id" , ProcessID , UInt64 ),
123 ENTRY_VALUE ( "name" , ProcessFile , CString , FileKind::Basename),
124 ENTRY_CHILDREN ( "file" , ProcessFile , None , g_file_child_entries),
127 static FormatEntity::Entry::Definition g_svar_child_entries[] =
129 ENTRY ( "*" , ParentString , None)
132 static FormatEntity::Entry::Definition g_var_child_entries[] =
134 ENTRY ( "*" , ParentString , None)
137 static FormatEntity::Entry::Definition g_thread_child_entries[] =
139 ENTRY ( "id" , ThreadID , UInt64 ),
140 ENTRY ( "protocol_id" , ThreadProtocolID , UInt64 ),
141 ENTRY ( "index" , ThreadIndexID , UInt32 ),
142 ENTRY_CHILDREN ( "info" , ThreadInfo , None , g_string_entry),
143 ENTRY ( "queue" , ThreadQueue , CString ),
144 ENTRY ( "name" , ThreadName , CString ),
145 ENTRY ( "stop-reason" , ThreadStopReason , CString ),
146 ENTRY ( "return-value" , ThreadReturnValue , CString ),
147 ENTRY ( "completed-expression", ThreadCompletedExpression , CString ),
150 static FormatEntity::Entry::Definition g_target_child_entries[] =
152 ENTRY ( "arch" , TargetArch , CString ),
155 #define _TO_STR2(_val) #_val
156 #define _TO_STR(_val) _TO_STR2(_val)
158 static FormatEntity::Entry::Definition g_ansi_fg_entries[] =
160 ENTRY_STRING ("black" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLACK) ANSI_ESC_END),
161 ENTRY_STRING ("red" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_RED) ANSI_ESC_END),
162 ENTRY_STRING ("green" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_GREEN) ANSI_ESC_END),
163 ENTRY_STRING ("yellow" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_YELLOW) ANSI_ESC_END),
164 ENTRY_STRING ("blue" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLUE) ANSI_ESC_END),
165 ENTRY_STRING ("purple" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_PURPLE) ANSI_ESC_END),
166 ENTRY_STRING ("cyan" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_CYAN) ANSI_ESC_END),
167 ENTRY_STRING ("white" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_WHITE) ANSI_ESC_END),
170 static FormatEntity::Entry::Definition g_ansi_bg_entries[] =
172 ENTRY_STRING ("black" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLACK) ANSI_ESC_END),
173 ENTRY_STRING ("red" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_RED) ANSI_ESC_END),
174 ENTRY_STRING ("green" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_GREEN) ANSI_ESC_END),
175 ENTRY_STRING ("yellow" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_YELLOW) ANSI_ESC_END),
176 ENTRY_STRING ("blue" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLUE) ANSI_ESC_END),
177 ENTRY_STRING ("purple" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_PURPLE) ANSI_ESC_END),
178 ENTRY_STRING ("cyan" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_CYAN) ANSI_ESC_END),
179 ENTRY_STRING ("white" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_WHITE) ANSI_ESC_END),
182 static FormatEntity::Entry::Definition g_ansi_entries[] =
184 ENTRY_CHILDREN ( "fg" , Invalid , None , g_ansi_fg_entries),
185 ENTRY_CHILDREN ( "bg" , Invalid , None , g_ansi_bg_entries),
186 ENTRY_STRING ( "normal" , ANSI_ESC_START _TO_STR(ANSI_CTRL_NORMAL) ANSI_ESC_END),
187 ENTRY_STRING ( "bold" , ANSI_ESC_START _TO_STR(ANSI_CTRL_BOLD) ANSI_ESC_END),
188 ENTRY_STRING ( "faint" , ANSI_ESC_START _TO_STR(ANSI_CTRL_FAINT) ANSI_ESC_END),
189 ENTRY_STRING ( "italic" , ANSI_ESC_START _TO_STR(ANSI_CTRL_ITALIC) ANSI_ESC_END),
190 ENTRY_STRING ( "underline" , ANSI_ESC_START _TO_STR(ANSI_CTRL_UNDERLINE) ANSI_ESC_END),
191 ENTRY_STRING ( "slow-blink" , ANSI_ESC_START _TO_STR(ANSI_CTRL_SLOW_BLINK) ANSI_ESC_END),
192 ENTRY_STRING ( "fast-blink" , ANSI_ESC_START _TO_STR(ANSI_CTRL_FAST_BLINK) ANSI_ESC_END),
193 ENTRY_STRING ( "negative" , ANSI_ESC_START _TO_STR(ANSI_CTRL_IMAGE_NEGATIVE) ANSI_ESC_END),
194 ENTRY_STRING ( "conceal" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CONCEAL) ANSI_ESC_END),
195 ENTRY_STRING ( "crossed-out" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CROSSED_OUT) ANSI_ESC_END),
199 static FormatEntity::Entry::Definition g_script_child_entries[] =
201 ENTRY ( "frame" , ScriptFrame , None),
202 ENTRY ( "process" , ScriptProcess , None),
203 ENTRY ( "target" , ScriptTarget , None),
204 ENTRY ( "thread" , ScriptThread , None),
205 ENTRY ( "var" , ScriptVariable , None),
206 ENTRY ( "svar" , ScriptVariableSynthetic , None),
207 ENTRY ( "thread" , ScriptThread , None),
210 static FormatEntity::Entry::Definition g_top_level_entries[] =
212 ENTRY_CHILDREN ("addr" , AddressLoadOrFile , UInt64 , g_addr_entries),
213 ENTRY ("addr-file-or-load" , AddressLoadOrFile , UInt64 ),
214 ENTRY_CHILDREN ("ansi" , Invalid , None , g_ansi_entries),
215 ENTRY ("current-pc-arrow" , CurrentPCArrow , CString ),
216 ENTRY_CHILDREN ("file" , File , CString , g_file_child_entries),
217 ENTRY ("language" , Lang , CString),
218 ENTRY_CHILDREN ("frame" , Invalid , None , g_frame_child_entries),
219 ENTRY_CHILDREN ("function" , Invalid , None , g_function_child_entries),
220 ENTRY_CHILDREN ("line" , Invalid , None , g_line_child_entries),
221 ENTRY_CHILDREN ("module" , Invalid , None , g_module_child_entries),
222 ENTRY_CHILDREN ("process" , Invalid , None , g_process_child_entries),
223 ENTRY_CHILDREN ("script" , Invalid , None , g_script_child_entries),
224 ENTRY_CHILDREN_KEEP_SEP ("svar" , VariableSynthetic , None , g_svar_child_entries),
225 ENTRY_CHILDREN ("thread" , Invalid , None , g_thread_child_entries),
226 ENTRY_CHILDREN ("target" , Invalid , None , g_target_child_entries),
227 ENTRY_CHILDREN_KEEP_SEP ("var" , Variable , None , g_var_child_entries),
230 static FormatEntity::Entry::Definition g_root = ENTRY_CHILDREN ("<root>", Root, None, g_top_level_entries);
233 FormatEntity::Entry::Entry (llvm::StringRef s) :
234 string (s.data(), s.size()),
239 fmt (lldb::eFormatDefault),
245 FormatEntity::Entry::Entry (char ch) :
251 fmt (lldb::eFormatDefault),
258 FormatEntity::Entry::AppendChar (char ch)
260 if (children.empty() || children.back().type != Entry::Type::String)
261 children.push_back(Entry(ch));
263 children.back().string.append(1, ch);
267 FormatEntity::Entry::AppendText (const llvm::StringRef &s)
269 if (children.empty() || children.back().type != Entry::Type::String)
270 children.push_back(Entry(s));
272 children.back().string.append(s.data(), s.size());
276 FormatEntity::Entry::AppendText (const char *cstr)
278 return AppendText (llvm::StringRef(cstr));
283 FormatEntity::Parse (const llvm::StringRef &format_str, Entry &entry)
286 entry.type = Entry::Type::Root;
287 llvm::StringRef modifiable_format (format_str);
288 return ParseInternal (modifiable_format, entry, 0);
291 #define ENUM_TO_CSTR(eee) case FormatEntity::Entry::Type::eee: return #eee
294 FormatEntity::Entry::TypeToCString (Type t)
298 ENUM_TO_CSTR(Invalid);
299 ENUM_TO_CSTR(ParentNumber);
300 ENUM_TO_CSTR(ParentString);
301 ENUM_TO_CSTR(InsertString);
303 ENUM_TO_CSTR(String);
305 ENUM_TO_CSTR(Variable);
306 ENUM_TO_CSTR(VariableSynthetic);
307 ENUM_TO_CSTR(ScriptVariable);
308 ENUM_TO_CSTR(ScriptVariableSynthetic);
309 ENUM_TO_CSTR(AddressLoad);
310 ENUM_TO_CSTR(AddressFile);
311 ENUM_TO_CSTR(AddressLoadOrFile);
312 ENUM_TO_CSTR(ProcessID);
313 ENUM_TO_CSTR(ProcessFile);
314 ENUM_TO_CSTR(ScriptProcess);
315 ENUM_TO_CSTR(ThreadID);
316 ENUM_TO_CSTR(ThreadProtocolID);
317 ENUM_TO_CSTR(ThreadIndexID);
318 ENUM_TO_CSTR(ThreadName);
319 ENUM_TO_CSTR(ThreadQueue);
320 ENUM_TO_CSTR(ThreadStopReason);
321 ENUM_TO_CSTR(ThreadReturnValue);
322 ENUM_TO_CSTR(ThreadCompletedExpression);
323 ENUM_TO_CSTR(ScriptThread);
324 ENUM_TO_CSTR(ThreadInfo);
325 ENUM_TO_CSTR(TargetArch);
326 ENUM_TO_CSTR(ScriptTarget);
327 ENUM_TO_CSTR(ModuleFile);
330 ENUM_TO_CSTR(FrameIndex);
331 ENUM_TO_CSTR(FrameRegisterPC);
332 ENUM_TO_CSTR(FrameRegisterSP);
333 ENUM_TO_CSTR(FrameRegisterFP);
334 ENUM_TO_CSTR(FrameRegisterFlags);
335 ENUM_TO_CSTR(FrameRegisterByName);
336 ENUM_TO_CSTR(ScriptFrame);
337 ENUM_TO_CSTR(FunctionID);
338 ENUM_TO_CSTR(FunctionDidChange);
339 ENUM_TO_CSTR(FunctionInitialFunction);
340 ENUM_TO_CSTR(FunctionName);
341 ENUM_TO_CSTR(FunctionNameWithArgs);
342 ENUM_TO_CSTR(FunctionNameNoArgs);
343 ENUM_TO_CSTR(FunctionAddrOffset);
344 ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
345 ENUM_TO_CSTR(FunctionLineOffset);
346 ENUM_TO_CSTR(FunctionPCOffset);
347 ENUM_TO_CSTR(FunctionInitial);
348 ENUM_TO_CSTR(FunctionChanged);
349 ENUM_TO_CSTR(FunctionIsOptimized);
350 ENUM_TO_CSTR(LineEntryFile);
351 ENUM_TO_CSTR(LineEntryLineNumber);
352 ENUM_TO_CSTR(LineEntryStartAddress);
353 ENUM_TO_CSTR(LineEntryEndAddress);
354 ENUM_TO_CSTR(CurrentPCArrow);
362 FormatEntity::Entry::Dump (Stream &s, int depth) const
364 s.Printf ("%*.*s%-20s: ", depth * 2, depth * 2, "", TypeToCString(type));
365 if (fmt != eFormatDefault)
366 s.Printf ("lldb-format = %s, ", FormatManager::GetFormatAsCString (fmt));
368 s.Printf ("string = \"%s\"", string.c_str());
369 if (!printf_format.empty())
370 s.Printf ("printf_format = \"%s\"", printf_format.c_str());
372 s.Printf ("number = %" PRIu64 " (0x%" PRIx64 "), ", number, number);
374 s.Printf ("deref = true, ");
376 for (const auto &child : children)
378 child.Dump(s, depth + 1);
383 template <typename T>
384 static bool RunScriptFormatKeyword(Stream &s,
385 const SymbolContext *sc,
386 const ExecutionContext *exe_ctx,
388 const char *script_function_name)
390 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
394 ScriptInterpreter *script_interpreter = target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
395 if (script_interpreter)
398 std::string script_output;
400 if (script_interpreter->RunScriptFormatKeyword(script_function_name, t, script_output, error) && error.Success())
402 s.Printf("%s", script_output.c_str());
407 s.Printf("<error: %s>",error.AsCString());
415 DumpAddress (Stream &s,
416 const SymbolContext *sc,
417 const ExecutionContext *exe_ctx,
419 bool print_file_addr_or_load_addr)
421 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
422 addr_t vaddr = LLDB_INVALID_ADDRESS;
423 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
424 vaddr = addr.GetLoadAddress (target);
425 if (vaddr == LLDB_INVALID_ADDRESS)
426 vaddr = addr.GetFileAddress ();
428 if (vaddr != LLDB_INVALID_ADDRESS)
431 if (exe_ctx && target)
433 addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
437 if (print_file_addr_or_load_addr)
439 ExecutionContextScope *exe_scope = NULL;
441 exe_scope = exe_ctx->GetBestExecutionContextScope();
442 addr.Dump (&s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, 0);
446 s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
454 DumpAddressOffsetFromFunction (Stream &s,
455 const SymbolContext *sc,
456 const ExecutionContext *exe_ctx,
457 const Address &format_addr,
460 bool print_zero_offsets)
462 if (format_addr.IsValid())
470 func_addr = sc->function->GetAddressRange().GetBaseAddress();
471 if (sc->block && !concrete_only)
473 // Check to make sure we aren't in an inline
474 // function. If we are, use the inline block
475 // range that contains "format_addr" since
476 // blocks can be discontiguous.
477 Block *inline_block = sc->block->GetContainingInlinedBlock ();
478 AddressRange inline_range;
479 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
480 func_addr = inline_range.GetBaseAddress();
483 else if (sc->symbol && sc->symbol->ValueIsAddress())
484 func_addr = sc->symbol->GetAddressRef();
487 if (func_addr.IsValid())
489 const char *addr_offset_padding = no_padding ? "" : " ";
491 if (func_addr.GetSection() == format_addr.GetSection())
493 addr_t func_file_addr = func_addr.GetFileAddress();
494 addr_t addr_file_addr = format_addr.GetFileAddress();
495 if (addr_file_addr > func_file_addr
496 || (addr_file_addr == func_file_addr && print_zero_offsets))
498 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_file_addr - func_file_addr);
500 else if (addr_file_addr < func_file_addr)
502 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_file_addr - addr_file_addr);
508 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
511 addr_t func_load_addr = func_addr.GetLoadAddress (target);
512 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
513 if (addr_load_addr > func_load_addr
514 || (addr_load_addr == func_load_addr && print_zero_offsets))
516 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_load_addr - func_load_addr);
518 else if (addr_load_addr < func_load_addr)
520 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_load_addr - addr_load_addr);
531 ScanBracketedRange (llvm::StringRef subpath,
532 size_t& close_bracket_index,
533 const char*& var_name_final_if_array_range,
534 int64_t& index_lower,
535 int64_t& index_higher)
537 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
538 close_bracket_index = llvm::StringRef::npos;
539 const size_t open_bracket_index = subpath.find('[');
540 if (open_bracket_index == llvm::StringRef::npos)
543 log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely");
547 close_bracket_index = subpath.find(']', open_bracket_index + 1);
549 if (close_bracket_index == llvm::StringRef::npos)
552 log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely");
557 var_name_final_if_array_range = subpath.data() + open_bracket_index;
559 if (close_bracket_index - open_bracket_index == 1)
562 log->Printf("[ScanBracketedRange] '[]' detected.. going from 0 to end of data");
567 const size_t separator_index = subpath.find('-', open_bracket_index + 1);
569 if (separator_index == llvm::StringRef::npos)
571 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
572 index_lower = ::strtoul (index_lower_cstr, NULL, 0);
573 index_higher = index_lower;
575 log->Printf("[ScanBracketedRange] [%" PRId64 "] detected, high index is same", index_lower);
579 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
580 const char *index_higher_cstr = subpath.data() + separator_index + 1;
581 index_lower = ::strtoul (index_lower_cstr, NULL, 0);
582 index_higher = ::strtoul (index_higher_cstr, NULL, 0);
584 log->Printf("[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected", index_lower, index_higher);
586 if (index_lower > index_higher && index_higher > 0)
589 log->Printf("[ScanBracketedRange] swapping indices");
590 const int64_t temp = index_lower;
591 index_lower = index_higher;
600 DumpFile (Stream &s, const FileSpec &file, FileKind file_kind)
604 case FileKind::FileError:
607 case FileKind::Basename:
608 if (file.GetFilename())
610 s << file.GetFilename();
615 case FileKind::Dirname:
616 if (file.GetDirectory())
618 s << file.GetDirectory();
623 case FileKind::Fullpath:
635 DumpRegister (Stream &s,
637 RegisterKind reg_kind,
644 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
648 const uint32_t lldb_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
649 if (lldb_reg_num != LLDB_INVALID_REGNUM)
651 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (lldb_reg_num);
654 RegisterValue reg_value;
655 if (reg_ctx->ReadRegister (reg_info, reg_value))
657 reg_value.Dump(&s, reg_info, false, false, format);
669 ExpandIndexedExpression (ValueObject* valobj,
674 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
675 const char* ptr_deref_format = "[%d]";
676 std::string ptr_deref_buffer(10,0);
677 ::sprintf(&ptr_deref_buffer[0], ptr_deref_format, index);
679 log->Printf("[ExpandIndexedExpression] name to deref: %s",ptr_deref_buffer.c_str());
680 const char* first_unparsed;
681 ValueObject::GetValueForExpressionPathOptions options;
682 ValueObject::ExpressionPathEndResultType final_value_type;
683 ValueObject::ExpressionPathScanEndReason reason_to_stop;
684 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
685 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.c_str(),
694 log->Printf("[ExpandIndexedExpression] ERROR: unparsed portion = %s, why stopping = %d,"
695 " final_value_type %d",
696 first_unparsed, reason_to_stop, final_value_type);
701 log->Printf("[ExpandIndexedExpression] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
702 " final_value_type %d",
703 first_unparsed, reason_to_stop, final_value_type);
709 ConvertValueObjectStyleToChar(ValueObject::ValueObjectRepresentationStyle style)
713 case ValueObject::eValueObjectRepresentationStyleLanguageSpecific: return '@';
714 case ValueObject::eValueObjectRepresentationStyleValue: return 'V';
715 case ValueObject::eValueObjectRepresentationStyleLocation: return 'L';
716 case ValueObject::eValueObjectRepresentationStyleSummary: return 'S';
717 case ValueObject::eValueObjectRepresentationStyleChildrenCount: return '#';
718 case ValueObject::eValueObjectRepresentationStyleType: return 'T';
719 case ValueObject::eValueObjectRepresentationStyleName: return 'N';
720 case ValueObject::eValueObjectRepresentationStyleExpressionPath: return '>';
726 DumpValue (Stream &s,
727 const SymbolContext *sc,
728 const ExecutionContext *exe_ctx,
729 const FormatEntity::Entry &entry,
735 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
736 Format custom_format = eFormatInvalid;
737 ValueObject::ValueObjectRepresentationStyle val_obj_display = entry.string.empty() ? ValueObject::eValueObjectRepresentationStyleValue : ValueObject::eValueObjectRepresentationStyleSummary;
739 bool do_deref_pointer = entry.deref;
740 bool is_script = false;
743 case FormatEntity::Entry::Type::ScriptVariable:
747 case FormatEntity::Entry::Type::Variable:
748 custom_format = entry.fmt;
749 val_obj_display = (ValueObject::ValueObjectRepresentationStyle)entry.number;
752 case FormatEntity::Entry::Type::ScriptVariableSynthetic:
755 case FormatEntity::Entry::Type::VariableSynthetic:
756 custom_format = entry.fmt;
757 val_obj_display = (ValueObject::ValueObjectRepresentationStyle)entry.number;
758 if (!valobj->IsSynthetic())
760 valobj = valobj->GetSyntheticValue().get();
761 if (valobj == nullptr)
773 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
774 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
775 ValueObject::GetValueForExpressionPathOptions options;
776 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().SetSyntheticChildrenTraversal(ValueObject::GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both);
777 ValueObject* target = NULL;
778 const char* var_name_final_if_array_range = NULL;
779 size_t close_bracket_index = llvm::StringRef::npos;
780 int64_t index_lower = -1;
781 int64_t index_higher = -1;
782 bool is_array_range = false;
783 const char* first_unparsed;
784 bool was_plain_var = false;
785 bool was_var_format = false;
786 bool was_var_indexed = false;
787 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
788 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
792 return RunScriptFormatKeyword (s, sc, exe_ctx, valobj, entry.string.c_str());
795 llvm::StringRef subpath (entry.string);
796 // simplest case ${var}, just print valobj's value
797 if (entry.string.empty())
799 if (entry.printf_format.empty() && entry.fmt == eFormatDefault && entry.number == ValueObject::eValueObjectRepresentationStyleValue)
800 was_plain_var = true;
802 was_var_format = true;
805 else // this is ${var.something} or multiple .something nested
807 if (entry.string[0] == '[')
808 was_var_indexed = true;
809 ScanBracketedRange (subpath,
811 var_name_final_if_array_range,
817 const std::string &expr_path = entry.string;
820 log->Printf("[Debugger::FormatPrompt] symbol to expand: %s",expr_path.c_str());
822 target = valobj->GetValueForExpressionPath(expr_path.c_str(),
832 log->Printf("[Debugger::FormatPrompt] ERROR: unparsed portion = %s, why stopping = %d,"
833 " final_value_type %d",
834 first_unparsed, reason_to_stop, final_value_type);
840 log->Printf("[Debugger::FormatPrompt] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
841 " final_value_type %d",
842 first_unparsed, reason_to_stop, final_value_type);
843 target = target->GetQualifiedRepresentationIfAvailable(target->GetDynamicValueType(), true).get();
848 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
849 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
851 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
853 if (do_deref_pointer && !is_array_range)
855 // I have not deref-ed yet, let's do it
856 // this happens when we are not going through GetValueForVariableExpressionPath
857 // to get to the target ValueObject
859 target = target->Dereference(error).get();
863 log->Printf("[Debugger::FormatPrompt] ERROR: %s\n", error.AsCString("unknown")); \
866 do_deref_pointer = false;
872 log->Printf("[Debugger::FormatPrompt] could not calculate target for prompt expression");
876 // we do not want to use the summary for a bitfield of type T:n
877 // if we were originally dealing with just a T - that would get
878 // us into an endless recursion
879 if (target->IsBitfield() && was_var_indexed)
881 // TODO: check for a (T:n)-specific summary - we should still obey that
882 StreamString bitfield_name;
883 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize());
884 lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false));
885 if (val_obj_display == ValueObject::eValueObjectRepresentationStyleSummary && !DataVisualization::GetSummaryForType(type_sp))
886 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
889 // TODO use flags for these
890 const uint32_t type_info_flags = target->GetCompilerType().GetTypeInfo(NULL);
891 bool is_array = (type_info_flags & eTypeIsArray) != 0;
892 bool is_pointer = (type_info_flags & eTypeIsPointer) != 0;
893 bool is_aggregate = target->GetCompilerType().IsAggregateType();
895 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) // this should be wrong, but there are some exceptions
897 StreamString str_temp;
899 log->Printf("[Debugger::FormatPrompt] I am into array || pointer && !range");
901 if (target->HasSpecialPrintableRepresentation(val_obj_display, custom_format))
903 // try to use the special cases
904 bool success = target->DumpPrintableRepresentation(str_temp,
908 log->Printf("[Debugger::FormatPrompt] special cases did%s match", success ? "" : "n't");
912 s << str_temp.GetData();
917 if (was_plain_var) // if ${var}
919 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
921 else if (is_pointer) // if pointer, value is the address stored
923 target->DumpPrintableRepresentation (s,
926 ValueObject::ePrintableRepresentationSpecialCasesDisable);
932 // if directly trying to print ${var}, and this is an aggregate, display a nice
933 // type @ location message
934 if (is_aggregate && was_plain_var)
936 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
940 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
941 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
943 s << "<invalid use of aggregate type>";
950 log->Printf("[Debugger::FormatPrompt] dumping ordinary printable output");
951 return target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
956 log->Printf("[Debugger::FormatPrompt] checking if I can handle as array");
957 if (!is_array && !is_pointer)
960 log->Printf("[Debugger::FormatPrompt] handle as array");
961 StreamString special_directions_stream;
962 llvm::StringRef special_directions;
963 if (close_bracket_index != llvm::StringRef::npos && subpath.size() > close_bracket_index)
965 ConstString additional_data (subpath.drop_front(close_bracket_index+1));
966 special_directions_stream.Printf("${%svar%s",
967 do_deref_pointer ? "*" : "",
968 additional_data.GetCString());
970 if (entry.fmt != eFormatDefault)
972 const char format_char = FormatManager::GetFormatAsFormatChar(entry.fmt);
973 if (format_char != '\0')
974 special_directions_stream.Printf("%%%c", format_char);
977 const char *format_cstr = FormatManager::GetFormatAsCString(entry.fmt);
978 special_directions_stream.Printf("%%%s", format_cstr);
981 else if (entry.number != 0)
983 const char style_char = ConvertValueObjectStyleToChar ((ValueObject::ValueObjectRepresentationStyle)entry.number);
985 special_directions_stream.Printf("%%%c", style_char);
987 special_directions_stream.PutChar('}');
988 special_directions = llvm::StringRef(special_directions_stream.GetString());
991 // let us display items index_lower thru index_higher of this array
994 if (index_higher < 0)
995 index_higher = valobj->GetNumChildren() - 1;
997 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
1000 for (int64_t index = index_lower;index<=index_higher; ++index)
1002 ValueObject* item = ExpandIndexedExpression (target,
1004 exe_ctx->GetFramePtr(),
1010 log->Printf("[Debugger::FormatPrompt] ERROR in getting child item at index %" PRId64, index);
1015 log->Printf("[Debugger::FormatPrompt] special_directions for child item: %s",special_directions.data() ? special_directions.data() : "");
1018 if (special_directions.empty())
1020 success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1024 success &= FormatEntity::FormatStringRef(special_directions, s, sc, exe_ctx, NULL, item, false, false);
1027 if (--max_num_children == 0)
1029 s.PutCString(", ...");
1033 if (index < index_higher)
1043 DumpRegister (Stream &s,
1045 const char *reg_name,
1051 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
1055 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
1058 RegisterValue reg_value;
1059 if (reg_ctx->ReadRegister (reg_info, reg_value))
1061 reg_value.Dump(&s, reg_info, false, false, format);
1071 FormatThreadExtendedInfoRecurse(const FormatEntity::Entry &entry,
1072 const StructuredData::ObjectSP &thread_info_dictionary,
1073 const SymbolContext *sc,
1074 const ExecutionContext *exe_ctx,
1077 llvm::StringRef path(entry.string);
1079 StructuredData::ObjectSP value = thread_info_dictionary->GetObjectForDotSeparatedPath (path);
1083 if (value->GetType() == StructuredData::Type::eTypeInteger)
1085 const char *token_format = "0x%4.4" PRIx64;
1086 if (!entry.printf_format.empty())
1087 token_format = entry.printf_format.c_str();
1088 s.Printf(token_format, value->GetAsInteger()->GetValue());
1091 else if (value->GetType() == StructuredData::Type::eTypeFloat)
1093 s.Printf ("%f", value->GetAsFloat()->GetValue());
1096 else if (value->GetType() == StructuredData::Type::eTypeString)
1098 s.Printf("%s", value->GetAsString()->GetValue().c_str());
1101 else if (value->GetType() == StructuredData::Type::eTypeArray)
1103 if (value->GetAsArray()->GetSize() > 0)
1105 s.Printf ("%zu", value->GetAsArray()->GetSize());
1109 else if (value->GetType() == StructuredData::Type::eTypeDictionary)
1111 s.Printf ("%zu", value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize());
1121 IsToken(const char *var_name_begin, const char *var)
1123 return (::strncmp (var_name_begin, var, strlen(var)) == 0);
1127 FormatEntity::FormatStringRef (const llvm::StringRef &format_str,
1129 const SymbolContext *sc,
1130 const ExecutionContext *exe_ctx,
1131 const Address *addr,
1132 ValueObject* valobj,
1133 bool function_changed,
1134 bool initial_function)
1136 if (!format_str.empty())
1138 FormatEntity::Entry root;
1139 Error error = FormatEntity::Parse(format_str, root);
1140 if (error.Success())
1142 return FormatEntity::Format (root,
1156 FormatEntity::FormatCString (const char *format,
1158 const SymbolContext *sc,
1159 const ExecutionContext *exe_ctx,
1160 const Address *addr,
1161 ValueObject* valobj,
1162 bool function_changed,
1163 bool initial_function)
1165 if (format && format[0])
1167 FormatEntity::Entry root;
1168 llvm::StringRef format_str(format);
1169 Error error = FormatEntity::Parse(format_str, root);
1170 if (error.Success())
1172 return FormatEntity::Format (root,
1186 FormatEntity::Format (const Entry &entry,
1188 const SymbolContext *sc,
1189 const ExecutionContext *exe_ctx,
1190 const Address *addr,
1191 ValueObject* valobj,
1192 bool function_changed,
1193 bool initial_function)
1197 case Entry::Type::Invalid:
1198 case Entry::Type::ParentNumber: // Only used for FormatEntity::Entry::Definition encoding
1199 case Entry::Type::ParentString: // Only used for FormatEntity::Entry::Definition encoding
1200 case Entry::Type::InsertString: // Only used for FormatEntity::Entry::Definition encoding
1203 case Entry::Type::Root:
1204 for (const auto &child : entry.children)
1213 initial_function) == false)
1215 return false; // If any item of root fails, then the formatting fails
1218 return true; // Only return true if all items succeeded
1220 case Entry::Type::String:
1221 s.PutCString(entry.string.c_str());
1224 case Entry::Type::Scope:
1226 StreamString scope_stream;
1227 bool success = false;
1228 for (const auto &child : entry.children)
1230 success = Format (child, scope_stream, sc, exe_ctx, addr, valobj, function_changed, initial_function);
1234 // Only if all items in a scope succeed, then do we
1235 // print the output into the main stream
1237 s.Write(scope_stream.GetString().data(), scope_stream.GetString().size());
1239 return true; // Scopes always successfully print themselves
1241 case Entry::Type::Variable:
1242 case Entry::Type::VariableSynthetic:
1243 case Entry::Type::ScriptVariable:
1244 case Entry::Type::ScriptVariableSynthetic:
1245 if (DumpValue(s, sc, exe_ctx, entry, valobj))
1249 case Entry::Type::AddressFile:
1250 case Entry::Type::AddressLoad:
1251 case Entry::Type::AddressLoadOrFile:
1252 if (addr && addr->IsValid() && DumpAddress(s, sc, exe_ctx, *addr, entry.type == Entry::Type::AddressLoadOrFile))
1256 case Entry::Type::ProcessID:
1259 Process *process = exe_ctx->GetProcessPtr();
1262 const char *format = "%" PRIu64;
1263 if (!entry.printf_format.empty())
1264 format = entry.printf_format.c_str();
1265 s.Printf(format, process->GetID());
1271 case Entry::Type::ProcessFile:
1274 Process *process = exe_ctx->GetProcessPtr();
1277 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1280 if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1287 case Entry::Type::ScriptProcess:
1290 Process *process = exe_ctx->GetProcessPtr();
1292 return RunScriptFormatKeyword (s, sc, exe_ctx, process, entry.string.c_str());
1297 case Entry::Type::ThreadID:
1300 Thread *thread = exe_ctx->GetThreadPtr();
1303 const char *format = "0x%4.4" PRIx64;
1304 if (!entry.printf_format.empty())
1306 // Watch for the special "tid" format...
1307 if (entry.printf_format == "tid")
1309 // TODO(zturner): Rather than hardcoding this to be platform specific, it should be controlled by a
1310 // setting and the default value of the setting can be different depending on the platform.
1311 Target &target = thread->GetProcess()->GetTarget();
1312 ArchSpec arch (target.GetArchitecture ());
1313 llvm::Triple::OSType ostype = arch.IsValid() ? arch.GetTriple().getOS() : llvm::Triple::UnknownOS;
1314 if ((ostype == llvm::Triple::FreeBSD) || (ostype == llvm::Triple::Linux))
1316 format = "%" PRIu64;
1321 format = entry.printf_format.c_str();
1324 s.Printf(format, thread->GetID());
1330 case Entry::Type::ThreadProtocolID:
1333 Thread *thread = exe_ctx->GetThreadPtr();
1336 const char *format = "0x%4.4" PRIx64;
1337 if (!entry.printf_format.empty())
1338 format = entry.printf_format.c_str();
1339 s.Printf(format, thread->GetProtocolID());
1345 case Entry::Type::ThreadIndexID:
1348 Thread *thread = exe_ctx->GetThreadPtr();
1351 const char *format = "%" PRIu32;
1352 if (!entry.printf_format.empty())
1353 format = entry.printf_format.c_str();
1354 s.Printf(format, thread->GetIndexID());
1360 case Entry::Type::ThreadName:
1363 Thread *thread = exe_ctx->GetThreadPtr();
1366 const char *cstr = thread->GetName();
1367 if (cstr && cstr[0])
1376 case Entry::Type::ThreadQueue:
1379 Thread *thread = exe_ctx->GetThreadPtr();
1382 const char *cstr = thread->GetQueueName();
1383 if (cstr && cstr[0])
1392 case Entry::Type::ThreadStopReason:
1395 Thread *thread = exe_ctx->GetThreadPtr();
1398 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1399 if (stop_info_sp && stop_info_sp->IsValid())
1401 const char *cstr = stop_info_sp->GetDescription();
1402 if (cstr && cstr[0])
1412 case Entry::Type::ThreadReturnValue:
1415 Thread *thread = exe_ctx->GetThreadPtr();
1418 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1419 if (stop_info_sp && stop_info_sp->IsValid())
1421 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1422 if (return_valobj_sp)
1424 return_valobj_sp->Dump(s);
1432 case Entry::Type::ThreadCompletedExpression:
1435 Thread *thread = exe_ctx->GetThreadPtr();
1438 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1439 if (stop_info_sp && stop_info_sp->IsValid())
1441 ExpressionVariableSP expression_var_sp = StopInfo::GetExpressionVariable (stop_info_sp);
1442 if (expression_var_sp && expression_var_sp->GetValueObject())
1444 expression_var_sp->GetValueObject()->Dump(s);
1452 case Entry::Type::ScriptThread:
1455 Thread *thread = exe_ctx->GetThreadPtr();
1457 return RunScriptFormatKeyword (s, sc, exe_ctx, thread, entry.string.c_str());
1461 case Entry::Type::ThreadInfo:
1464 Thread *thread = exe_ctx->GetThreadPtr();
1467 StructuredData::ObjectSP object_sp = thread->GetExtendedInfo();
1468 if (object_sp && object_sp->GetType() == StructuredData::Type::eTypeDictionary)
1470 if (FormatThreadExtendedInfoRecurse (entry, object_sp, sc, exe_ctx, s))
1477 case Entry::Type::TargetArch:
1480 Target *target = exe_ctx->GetTargetPtr();
1483 const ArchSpec &arch = target->GetArchitecture ();
1486 s.PutCString (arch.GetArchitectureName());
1493 case Entry::Type::ScriptTarget:
1496 Target *target = exe_ctx->GetTargetPtr();
1498 return RunScriptFormatKeyword (s, sc, exe_ctx, target, entry.string.c_str());
1502 case Entry::Type::ModuleFile:
1505 Module *module = sc->module_sp.get();
1508 if (DumpFile(s, module->GetFileSpec(), (FileKind)entry.number))
1514 case Entry::Type::File:
1517 CompileUnit *cu = sc->comp_unit;
1520 // CompileUnit is a FileSpec
1521 if (DumpFile(s, *cu, (FileKind)entry.number))
1527 case Entry::Type::Lang:
1530 CompileUnit *cu = sc->comp_unit;
1533 const char *lang_name = Language::GetNameForLanguageType(cu->GetLanguage());
1536 s.PutCString(lang_name);
1543 case Entry::Type::FrameIndex:
1546 StackFrame *frame = exe_ctx->GetFramePtr();
1549 const char *format = "%" PRIu32;
1550 if (!entry.printf_format.empty())
1551 format = entry.printf_format.c_str();
1552 s.Printf(format, frame->GetFrameIndex());
1558 case Entry::Type::FrameRegisterPC:
1561 StackFrame *frame = exe_ctx->GetFramePtr();
1564 const Address &pc_addr = frame->GetFrameCodeAddress();
1565 if (pc_addr.IsValid())
1567 if (DumpAddress(s, sc, exe_ctx, pc_addr, false))
1574 case Entry::Type::FrameRegisterSP:
1577 StackFrame *frame = exe_ctx->GetFramePtr();
1580 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, (lldb::Format)entry.number))
1586 case Entry::Type::FrameRegisterFP:
1589 StackFrame *frame = exe_ctx->GetFramePtr();
1592 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, (lldb::Format)entry.number))
1598 case Entry::Type::FrameRegisterFlags:
1601 StackFrame *frame = exe_ctx->GetFramePtr();
1604 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, (lldb::Format)entry.number))
1611 case Entry::Type::FrameRegisterByName:
1614 StackFrame *frame = exe_ctx->GetFramePtr();
1617 if (DumpRegister (s, frame, entry.string.c_str(), (lldb::Format)entry.number))
1623 case Entry::Type::ScriptFrame:
1626 StackFrame *frame = exe_ctx->GetFramePtr();
1628 return RunScriptFormatKeyword (s, sc, exe_ctx, frame, entry.string.c_str());
1632 case Entry::Type::FunctionID:
1637 s.Printf("function{0x%8.8" PRIx64 "}", sc->function->GetID());
1640 else if (sc->symbol)
1642 s.Printf("symbol[%u]", sc->symbol->GetID());
1648 case Entry::Type::FunctionDidChange:
1649 return function_changed;
1651 case Entry::Type::FunctionInitialFunction:
1652 return initial_function;
1654 case Entry::Type::FunctionName:
1656 Language *language_plugin = nullptr;
1657 bool language_plugin_handled = false;
1660 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1661 else if (sc->symbol)
1662 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1663 if (language_plugin)
1665 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1667 Language::FunctionNameRepresentation::eName,
1670 if (language_plugin_handled)
1672 s.PutCString(ss.GetData());
1677 const char *name = NULL;
1679 name = sc->function->GetName().AsCString (NULL);
1680 else if (sc->symbol)
1681 name = sc->symbol->GetName().AsCString (NULL);
1688 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1691 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1694 s.PutCString(" [inlined] ");
1695 inline_info->GetName(sc->function->GetLanguage()).Dump(&s);
1705 case Entry::Type::FunctionNameNoArgs:
1707 Language *language_plugin = nullptr;
1708 bool language_plugin_handled = false;
1711 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1712 else if (sc->symbol)
1713 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1714 if (language_plugin)
1716 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1718 Language::FunctionNameRepresentation::eNameWithNoArgs,
1721 if (language_plugin_handled)
1723 s.PutCString(ss.GetData());
1730 name = sc->function->GetNameNoArguments();
1731 else if (sc->symbol)
1732 name = sc->symbol->GetNameNoArguments();
1735 s.PutCString(name.GetCString());
1742 case Entry::Type::FunctionNameWithArgs:
1744 Language *language_plugin = nullptr;
1745 bool language_plugin_handled = false;
1748 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1749 else if (sc->symbol)
1750 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1751 if (language_plugin)
1753 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1755 Language::FunctionNameRepresentation::eNameWithArgs,
1758 if (language_plugin_handled)
1760 s.PutCString(ss.GetData());
1765 // Print the function name with arguments in it
1768 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL;
1769 const char *cstr = sc->function->GetName().AsCString (NULL);
1772 const InlineFunctionInfo *inline_info = NULL;
1773 VariableListSP variable_list_sp;
1774 bool get_function_vars = true;
1777 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1781 get_function_vars = false;
1782 inline_info = sc->block->GetInlinedFunctionInfo();
1784 variable_list_sp = inline_block->GetBlockVariableList (true);
1788 if (get_function_vars)
1790 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1795 s.PutCString (cstr);
1796 s.PutCString (" [inlined] ");
1797 cstr = inline_info->GetName(sc->function->GetLanguage()).GetCString();
1801 if (variable_list_sp)
1802 variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, args);
1803 if (args.GetSize() > 0)
1805 const char *open_paren = strchr (cstr, '(');
1806 const char *close_paren = nullptr;
1807 const char *generic = strchr(cstr, '<');
1808 // if before the arguments list begins there is a template sign
1809 // then scan to the end of the generic args before you try to find
1810 // the arguments list
1811 if (generic && open_paren && generic < open_paren)
1813 int generic_depth = 1;
1816 *generic && generic_depth > 0;
1819 if (*generic == '<')
1821 if (*generic == '>')
1825 open_paren = strchr(generic, '(');
1827 open_paren = nullptr;
1831 if (IsToken (open_paren, "(anonymous namespace)"))
1833 open_paren = strchr (open_paren + strlen("(anonymous namespace)"), '(');
1835 close_paren = strchr (open_paren, ')');
1838 close_paren = strchr (open_paren, ')');
1842 s.Write(cstr, open_paren - cstr + 1);
1845 s.PutCString (cstr);
1848 const size_t num_args = args.GetSize();
1849 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1853 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1854 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1856 const char *var_representation = nullptr;
1857 const char *var_name = var_value_sp->GetName().GetCString();
1858 if (var_value_sp->GetCompilerType().IsValid())
1860 if (var_value_sp && exe_scope->CalculateTarget())
1861 var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(exe_scope->CalculateTarget()->TargetProperties::GetPreferDynamicValue(),
1862 exe_scope->CalculateTarget()->TargetProperties::GetEnableSyntheticValue());
1863 if (var_value_sp->GetCompilerType().IsAggregateType() &&
1864 DataVisualization::ShouldPrintAsOneLiner(*var_value_sp.get()))
1866 static StringSummaryFormat format(TypeSummaryImpl::Flags()
1867 .SetHideItemNames(false)
1868 .SetShowMembersOneLiner(true),
1870 format.FormatObject(var_value_sp.get(), buffer, TypeSummaryOptions());
1871 var_representation = buffer.c_str();
1874 var_value_sp->DumpPrintableRepresentation(ss,
1875 ValueObject::ValueObjectRepresentationStyle::eValueObjectRepresentationStyleSummary,
1877 ValueObject::PrintableRepresentationSpecialCases::ePrintableRepresentationSpecialCasesAllow,
1881 if (ss.GetData() && ss.GetSize())
1882 var_representation = ss.GetData();
1884 s.PutCString (", ");
1885 if (var_value_sp->GetError().Success())
1887 if (var_representation)
1888 s.Printf ("%s=%s", var_name, var_representation);
1890 s.Printf ("%s=%s at %s", var_name, var_value_sp->GetTypeName().GetCString(), var_value_sp->GetLocationAsCString());
1893 s.Printf ("%s=<unavailable>", var_name);
1897 s.PutCString (close_paren);
1909 else if (sc->symbol)
1911 const char *cstr = sc->symbol->GetName().AsCString (NULL);
1922 case Entry::Type::FunctionAddrOffset:
1925 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, *addr, false, false, false))
1930 case Entry::Type::FunctionAddrOffsetConcrete:
1933 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, *addr, true, true, true))
1938 case Entry::Type::FunctionLineOffset:
1939 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, sc->line_entry.range.GetBaseAddress(), false, false, false))
1943 case Entry::Type::FunctionPCOffset:
1946 StackFrame *frame = exe_ctx->GetFramePtr();
1949 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, frame->GetFrameCodeAddress(), false, false, false))
1955 case Entry::Type::FunctionChanged:
1956 return function_changed == true;
1958 case Entry::Type::FunctionIsOptimized:
1960 bool is_optimized = false;
1961 if (sc->function && sc->function->GetIsOptimized())
1963 is_optimized = true;
1965 return is_optimized;
1968 case Entry::Type::FunctionInitial:
1969 return initial_function == true;
1971 case Entry::Type::LineEntryFile:
1972 if (sc && sc->line_entry.IsValid())
1974 Module *module = sc->module_sp.get();
1977 if (DumpFile(s, sc->line_entry.file, (FileKind)entry.number))
1983 case Entry::Type::LineEntryLineNumber:
1984 if (sc && sc->line_entry.IsValid())
1986 const char *format = "%" PRIu32;
1987 if (!entry.printf_format.empty())
1988 format = entry.printf_format.c_str();
1989 s.Printf(format, sc->line_entry.line);
1994 case Entry::Type::LineEntryStartAddress:
1995 case Entry::Type::LineEntryEndAddress:
1996 if (sc && sc->line_entry.range.GetBaseAddress().IsValid())
1998 Address addr = sc->line_entry.range.GetBaseAddress();
2000 if (entry.type == Entry::Type::LineEntryEndAddress)
2001 addr.Slide(sc->line_entry.range.GetByteSize());
2002 if (DumpAddress(s, sc, exe_ctx, addr, false))
2007 case Entry::Type::CurrentPCArrow:
2008 if (addr && exe_ctx && exe_ctx->GetFramePtr())
2010 RegisterContextSP reg_ctx = exe_ctx->GetFramePtr()->GetRegisterContextSP();
2013 addr_t pc_loadaddr = reg_ctx->GetPC();
2014 if (pc_loadaddr != LLDB_INVALID_ADDRESS)
2017 pc.SetLoadAddress (pc_loadaddr, exe_ctx->GetTargetPtr());
2034 DumpCommaSeparatedChildEntryNames (Stream &s, const FormatEntity::Entry::Definition *parent)
2036 if (parent->children)
2038 const size_t n = parent->num_children;
2039 for (size_t i=0; i<n; ++i)
2043 s.Printf ("\"%s\"", parent->children[i].name);
2052 ParseEntry (const llvm::StringRef &format_str,
2053 const FormatEntity::Entry::Definition *parent,
2054 FormatEntity::Entry &entry)
2058 const size_t sep_pos = format_str.find_first_of(".[:");
2059 const char sep_char = (sep_pos == llvm::StringRef::npos) ? '\0' : format_str[sep_pos];
2060 llvm::StringRef key = format_str.substr(0, sep_pos);
2062 const size_t n = parent->num_children;
2063 for (size_t i=0; i<n; ++i)
2065 const FormatEntity::Entry::Definition *entry_def = parent->children + i;
2066 if (key.equals(entry_def->name) || entry_def->name[0] == '*')
2068 llvm::StringRef value;
2070 value = format_str.substr(sep_pos + (entry_def->keep_separator ? 0 : 1));
2071 switch (entry_def->type)
2073 case FormatEntity::Entry::Type::ParentString:
2074 entry.string = format_str.str();
2075 return error; // Success
2077 case FormatEntity::Entry::Type::ParentNumber:
2078 entry.number = entry_def->data;
2079 return error; // Success
2081 case FormatEntity::Entry::Type::InsertString:
2082 entry.type = entry_def->type;
2083 entry.string = entry_def->string;
2084 return error; // Success
2087 entry.type = entry_def->type;
2093 if (entry_def->type == FormatEntity::Entry::Type::Invalid)
2095 if (entry_def->children)
2097 StreamString error_strm;
2098 error_strm.Printf("'%s' can't be specified on its own, you must access one of its children: ", entry_def->name);
2099 DumpCommaSeparatedChildEntryNames (error_strm, entry_def);
2100 error.SetErrorStringWithFormat("%s", error_strm.GetString().c_str());
2102 else if (sep_char == ':')
2104 // Any value whose separator is a with a ':' means this value has a string argument
2105 // that needs to be stored in the entry (like "${script.var:}").
2106 // In this case the string value is the empty string which is ok.
2110 error.SetErrorStringWithFormat("%s", "invalid entry definitions");
2116 if (entry_def->children)
2118 error = ParseEntry (value, entry_def, entry);
2120 else if (sep_char == ':')
2122 // Any value whose separator is a with a ':' means this value has a string argument
2123 // that needs to be stored in the entry (like "${script.var:modulename.function}")
2124 entry.string = value.str();
2128 error.SetErrorStringWithFormat("'%s' followed by '%s' but it has no children",
2130 value.str().c_str());
2136 StreamString error_strm;
2137 if (parent->type == FormatEntity::Entry::Type::Root)
2138 error_strm.Printf("invalid top level item '%s'. Valid top level items are: ", key.str().c_str());
2140 error_strm.Printf("invalid member '%s' in '%s'. Valid members are: ", key.str().c_str(), parent->name);
2141 DumpCommaSeparatedChildEntryNames (error_strm, parent);
2142 error.SetErrorStringWithFormat("%s", error_strm.GetString().c_str());
2147 static const FormatEntity::Entry::Definition *
2148 FindEntry (const llvm::StringRef &format_str, const FormatEntity::Entry::Definition *parent, llvm::StringRef &remainder)
2152 std::pair<llvm::StringRef, llvm::StringRef> p = format_str.split('.');
2153 const size_t n = parent->num_children;
2154 for (size_t i=0; i<n; ++i)
2156 const FormatEntity::Entry::Definition *entry_def = parent->children + i;
2157 if (p.first.equals(entry_def->name) || entry_def->name[0] == '*')
2159 if (p.second.empty())
2161 if (format_str.back() == '.')
2162 remainder = format_str.drop_front(format_str.size() - 1);
2164 remainder = llvm::StringRef(); // Exact match
2169 if (entry_def->children)
2171 return FindEntry (p.second, entry_def, remainder);
2175 remainder = p.second;
2181 remainder = format_str;
2186 FormatEntity::ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint32_t depth)
2189 while (!format.empty() && error.Success())
2191 const size_t non_special_chars = format.find_first_of("${}\\");
2193 if (non_special_chars == llvm::StringRef::npos)
2195 // No special characters, just string bytes so add them and we are done
2196 parent_entry.AppendText(format);
2200 if (non_special_chars > 0)
2202 // We have a special character, so add all characters before these as a plain string
2203 parent_entry.AppendText(format.substr(0,non_special_chars));
2204 format = format.drop_front(non_special_chars);
2214 format = format.drop_front(); // Skip the '{'
2215 Entry scope_entry(Entry::Type::Scope);
2216 error = FormatEntity::ParseInternal (format, scope_entry, depth+1);
2219 parent_entry.AppendEntry(std::move(scope_entry));
2225 error.SetErrorString("unmatched '}' character");
2227 format = format.drop_front(); // Skip the '}' as we are at the end of the scope
2232 format = format.drop_front(); // Skip the '\' character
2235 error.SetErrorString("'\\' character was not followed by another character");
2239 const char desens_char = format[0];
2240 format = format.drop_front(); // Skip the desensitized char character
2241 switch (desens_char)
2243 case 'a': parent_entry.AppendChar('\a'); break;
2244 case 'b': parent_entry.AppendChar('\b'); break;
2245 case 'f': parent_entry.AppendChar('\f'); break;
2246 case 'n': parent_entry.AppendChar('\n'); break;
2247 case 'r': parent_entry.AppendChar('\r'); break;
2248 case 't': parent_entry.AppendChar('\t'); break;
2249 case 'v': parent_entry.AppendChar('\v'); break;
2250 case '\'': parent_entry.AppendChar('\''); break;
2251 case '\\': parent_entry.AppendChar('\\'); break;
2253 // 1 to 3 octal chars
2255 // Make a string that can hold onto the initial zero char,
2256 // up to 3 octal digits, and a terminating NULL.
2257 char oct_str[5] = { 0, 0, 0, 0, 0 };
2260 for (i=0; (format[i] >= '0' && format[i] <= '7') && i<4; ++i)
2261 oct_str[i] = format[i];
2263 // We don't want to consume the last octal character since
2264 // the main for loop will do this for us, so we advance p by
2265 // one less than i (even if i is zero)
2266 format = format.drop_front(i);
2267 unsigned long octal_value = ::strtoul (oct_str, NULL, 8);
2268 if (octal_value <= UINT8_MAX)
2270 parent_entry.AppendChar((char)octal_value);
2274 error.SetErrorString("octal number is larger than a single byte");
2281 // hex number in the format
2282 if (isxdigit(format[0]))
2284 // Make a string that can hold onto two hex chars plus a
2286 char hex_str[3] = { 0,0,0 };
2287 hex_str[0] = format[0];
2289 format = format.drop_front();
2291 if (isxdigit(format[0]))
2293 hex_str[1] = format[0];
2294 format = format.drop_front();
2297 unsigned long hex_value = strtoul (hex_str, NULL, 16);
2298 if (hex_value <= UINT8_MAX)
2300 parent_entry.AppendChar((char)hex_value);
2304 error.SetErrorString("hex number is larger than a single byte");
2310 parent_entry.AppendChar(desens_char);
2315 // Just desensitize any other character by just printing what
2316 // came after the '\'
2317 parent_entry.AppendChar(desens_char);
2324 if (format.size() == 1)
2326 // '$' at the end of a format string, just print the '$'
2327 parent_entry.AppendText("$");
2331 format = format.drop_front(); // Skip the '$'
2333 if (format[0] == '{')
2335 format = format.drop_front(); // Skip the '{'
2337 llvm::StringRef variable, variable_format;
2338 error = FormatEntity::ExtractVariableInfo (format, variable, variable_format);
2341 bool verify_is_thread_id = false;
2343 if (!variable_format.empty())
2345 entry.printf_format = variable_format.str();
2347 // If the format contains a '%' we are going to assume this is
2348 // a printf style format. So if you want to format your thread ID
2349 // using "0x%llx" you can use:
2350 // ${thread.id%0x%llx}
2352 // If there is no '%' in the format, then it is assumed to be a
2353 // LLDB format name, or one of the extended formats specified in
2354 // the switch statement below.
2356 if (entry.printf_format.find('%') == std::string::npos)
2358 bool clear_printf = false;
2360 if (FormatManager::GetFormatFromCString(entry.printf_format.c_str(),
2364 // We have an LLDB format, so clear the printf format
2365 clear_printf = true;
2367 else if (entry.printf_format.size() == 1)
2369 switch (entry.printf_format[0])
2371 case '@': // if this is an @ sign, print ObjC description
2372 entry.number = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
2373 clear_printf = true;
2375 case 'V': // if this is a V, print the value using the default format
2376 entry.number = ValueObject::eValueObjectRepresentationStyleValue;
2377 clear_printf = true;
2379 case 'L': // if this is an L, print the location of the value
2380 entry.number = ValueObject::eValueObjectRepresentationStyleLocation;
2381 clear_printf = true;
2383 case 'S': // if this is an S, print the summary after all
2384 entry.number = ValueObject::eValueObjectRepresentationStyleSummary;
2385 clear_printf = true;
2387 case '#': // if this is a '#', print the number of children
2388 entry.number = ValueObject::eValueObjectRepresentationStyleChildrenCount;
2389 clear_printf = true;
2391 case 'T': // if this is a 'T', print the type
2392 entry.number = ValueObject::eValueObjectRepresentationStyleType;
2393 clear_printf = true;
2395 case 'N': // if this is a 'N', print the name
2396 entry.number = ValueObject::eValueObjectRepresentationStyleName;
2397 clear_printf = true;
2399 case '>': // if this is a '>', print the expression path
2400 entry.number = ValueObject::eValueObjectRepresentationStyleExpressionPath;
2401 clear_printf = true;
2404 error.SetErrorStringWithFormat("invalid format: '%s'", entry.printf_format.c_str());
2408 else if (FormatManager::GetFormatFromCString(entry.printf_format.c_str(),
2412 clear_printf = true;
2414 else if (entry.printf_format == "tid")
2416 verify_is_thread_id = true;
2420 error.SetErrorStringWithFormat("invalid format: '%s'", entry.printf_format.c_str());
2424 // Our format string turned out to not be a printf style format
2425 // so lets clear the string
2427 entry.printf_format.clear();
2431 // Check for dereferences
2432 if (variable[0] == '*')
2435 variable = variable.drop_front();
2438 error = ParseEntry (variable, &g_root, entry);
2442 if (verify_is_thread_id)
2444 if (entry.type != Entry::Type::ThreadID &&
2445 entry.type != Entry::Type::ThreadProtocolID)
2447 error.SetErrorString("the 'tid' format can only be used on ${thread.id} and ${thread.protocol_id}");
2453 case Entry::Type::Variable:
2454 case Entry::Type::VariableSynthetic:
2455 if (entry.number == 0)
2457 if (entry.string.empty())
2458 entry.number = ValueObject::eValueObjectRepresentationStyleValue;
2460 entry.number = ValueObject::eValueObjectRepresentationStyleSummary;
2464 // Make sure someone didn't try to dereference anything but ${var} or ${svar}
2467 error.SetErrorStringWithFormat("${%s} can't be dereferenced, only ${var} and ${svar} can.", variable.str().c_str());
2471 // Check if this entry just wants to insert a constant string
2472 // value into the parent_entry, if so, insert the string with
2473 // AppendText, else append the entry to the parent_entry.
2474 if (entry.type == Entry::Type::InsertString)
2475 parent_entry.AppendText(entry.string.c_str());
2477 parent_entry.AppendEntry(std::move(entry));
2488 FormatEntity::ExtractVariableInfo (llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
2491 variable_name = llvm::StringRef();
2492 variable_format = llvm::StringRef();
2494 const size_t paren_pos = format_str.find('}');
2495 if (paren_pos != llvm::StringRef::npos)
2497 const size_t percent_pos = format_str.find('%');
2498 if (percent_pos < paren_pos)
2500 if (percent_pos > 0)
2502 if (percent_pos > 1)
2503 variable_name = format_str.substr(0, percent_pos);
2504 variable_format = format_str.substr(percent_pos + 1, paren_pos - (percent_pos + 1));
2509 variable_name = format_str.substr(0, paren_pos);
2511 // Strip off elements and the formatting and the trailing '}'
2512 format_str = format_str.substr(paren_pos + 1);
2516 error.SetErrorStringWithFormat("missing terminating '}' character for '${%s'", format_str.str().c_str());
2522 FormatEntity::FormatFileSpec (const FileSpec &file_spec, Stream &s, llvm::StringRef variable_name, llvm::StringRef variable_format)
2524 if (variable_name.empty() || variable_name.equals(".fullpath"))
2529 else if (variable_name.equals(".basename"))
2531 s.PutCString(file_spec.GetFilename().AsCString(""));
2534 else if (variable_name.equals(".dirname"))
2536 s.PutCString(file_spec.GetFilename().AsCString(""));
2543 MakeMatch (const llvm::StringRef &prefix, const char *suffix)
2545 std::string match(prefix.str());
2546 match.append(suffix);
2551 AddMatches (const FormatEntity::Entry::Definition *def,
2552 const llvm::StringRef &prefix,
2553 const llvm::StringRef &match_prefix,
2554 StringList &matches)
2556 const size_t n = def->num_children;
2559 for (size_t i=0; i<n; ++i)
2561 std::string match = prefix.str();
2562 if (match_prefix.empty())
2563 matches.AppendString(MakeMatch (prefix, def->children[i].name));
2564 else if (strncmp(def->children[i].name, match_prefix.data(), match_prefix.size()) == 0)
2565 matches.AppendString(MakeMatch (prefix, def->children[i].name + match_prefix.size()));
2570 FormatEntity::AutoComplete (const char *s,
2571 int match_start_point,
2572 int max_return_elements,
2573 bool &word_complete,
2574 StringList &matches)
2576 word_complete = false;
2577 llvm::StringRef str(s + match_start_point);
2580 const size_t dollar_pos = str.rfind('$');
2581 if (dollar_pos != llvm::StringRef::npos)
2583 // Hitting TAB after $ at the end of the string add a "{"
2584 if (dollar_pos == str.size() - 1)
2586 std::string match = str.str();
2588 matches.AppendString(std::move(match));
2590 else if (str[dollar_pos + 1] == '{')
2592 const size_t close_pos = str.find('}', dollar_pos + 2);
2593 if (close_pos == llvm::StringRef::npos)
2595 const size_t format_pos = str.find('%', dollar_pos + 2);
2596 if (format_pos == llvm::StringRef::npos)
2598 llvm::StringRef partial_variable (str.substr(dollar_pos + 2));
2599 if (partial_variable.empty())
2601 // Suggest all top level entites as we are just past "${"
2602 AddMatches(&g_root, str, llvm::StringRef(), matches);
2606 // We have a partially specified variable, find it
2607 llvm::StringRef remainder;
2608 const FormatEntity::Entry::Definition* entry_def = FindEntry (partial_variable, &g_root, remainder);
2611 const size_t n = entry_def->num_children;
2613 if (remainder.empty())
2618 // "${thread.info" <TAB>
2619 matches.AppendString(MakeMatch(str, "."));
2623 // "${thread.id" <TAB>
2624 matches.AppendString(MakeMatch (str, "}"));
2625 word_complete = true;
2628 else if (remainder.equals("."))
2630 // "${thread." <TAB>
2631 AddMatches(entry_def, str, llvm::StringRef(), matches);
2635 // We have a partial match
2637 AddMatches(entry_def, str, remainder, matches);
2645 return matches.GetSize();