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"
14 // Other libraries and framework includes
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
19 #include "lldb/Core/Address.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/Module.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamString.h"
24 #include "lldb/Core/ValueObject.h"
25 #include "lldb/Core/ValueObjectVariable.h"
26 #include "lldb/DataFormatters/DataVisualization.h"
27 #include "lldb/DataFormatters/FormatManager.h"
28 #include "lldb/DataFormatters/ValueObjectPrinter.h"
29 #include "lldb/Expression/ExpressionVariable.h"
30 #include "lldb/Host/FileSpec.h"
31 #include "lldb/Interpreter/CommandInterpreter.h"
32 #include "lldb/Symbol/Block.h"
33 #include "lldb/Symbol/CompileUnit.h"
34 #include "lldb/Symbol/Function.h"
35 #include "lldb/Symbol/LineEntry.h"
36 #include "lldb/Symbol/Symbol.h"
37 #include "lldb/Symbol/VariableList.h"
38 #include "lldb/Target/ExecutionContext.h"
39 #include "lldb/Target/Language.h"
40 #include "lldb/Target/Process.h"
41 #include "lldb/Target/RegisterContext.h"
42 #include "lldb/Target/SectionLoadList.h"
43 #include "lldb/Target/StackFrame.h"
44 #include "lldb/Target/StopInfo.h"
45 #include "lldb/Target/Target.h"
46 #include "lldb/Target/Thread.h"
47 #include "lldb/Utility/AnsiTerminal.h"
50 using namespace lldb_private;
60 #define ENTRY(n,t,f) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, 0, nullptr, false}
61 #define ENTRY_VALUE(n,t,f,v) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, v, 0, nullptr, false}
62 #define ENTRY_CHILDREN(n,t,f,c) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, llvm::array_lengthof(c), c, false}
63 #define ENTRY_CHILDREN_KEEP_SEP(n,t,f,c) { n, nullptr, FormatEntity::Entry::Type::t, FormatEntity::Entry::FormatType::f, 0, llvm::array_lengthof(c), c, true}
64 #define ENTRY_STRING(n,s) { n, s, FormatEntity::Entry::Type::InsertString, FormatEntity::Entry::FormatType::None, 0, 0, nullptr, false}
65 static FormatEntity::Entry::Definition g_string_entry[] =
67 ENTRY("*", ParentString, None)
70 static FormatEntity::Entry::Definition g_addr_entries[] =
72 ENTRY ("load", AddressLoad , UInt64),
73 ENTRY ("file", AddressFile , UInt64),
74 ENTRY ("load", AddressLoadOrFile, UInt64),
77 static FormatEntity::Entry::Definition g_file_child_entries[] =
79 ENTRY_VALUE("basename", ParentNumber, CString, FileKind::Basename),
80 ENTRY_VALUE("dirname", ParentNumber, CString, FileKind::Dirname),
81 ENTRY_VALUE("fullpath", ParentNumber, CString, FileKind::Fullpath)
84 static FormatEntity::Entry::Definition g_frame_child_entries[] =
86 ENTRY ("index", FrameIndex , UInt32),
87 ENTRY ("pc" , FrameRegisterPC , UInt64),
88 ENTRY ("fp" , FrameRegisterFP , UInt64),
89 ENTRY ("sp" , FrameRegisterSP , UInt64),
90 ENTRY ("flags", FrameRegisterFlags, UInt64),
91 ENTRY_CHILDREN ("reg", FrameRegisterByName, UInt64, g_string_entry),
94 static FormatEntity::Entry::Definition g_function_child_entries[] =
96 ENTRY ("id" , FunctionID , UInt64),
97 ENTRY ("name" , FunctionName , CString),
98 ENTRY ("name-without-args" , FunctionNameNoArgs , CString),
99 ENTRY ("name-with-args" , FunctionNameWithArgs , CString),
100 ENTRY ("addr-offset" , FunctionAddrOffset , UInt64),
101 ENTRY ("concrete-only-addr-offset-no-padding", FunctionAddrOffsetConcrete, UInt64),
102 ENTRY ("line-offset" , FunctionLineOffset , UInt64),
103 ENTRY ("pc-offset" , FunctionPCOffset , UInt64),
104 ENTRY ("initial-function" , FunctionInitial , None),
105 ENTRY ("changed" , FunctionChanged , None),
106 ENTRY ("is-optimized" , FunctionIsOptimized , None)
109 static FormatEntity::Entry::Definition g_line_child_entries[] =
111 ENTRY_CHILDREN("file", LineEntryFile , None , g_file_child_entries),
112 ENTRY("number" , LineEntryLineNumber , UInt32),
113 ENTRY("start-addr" , LineEntryStartAddress, UInt64),
114 ENTRY("end-addr" , LineEntryEndAddress , UInt64),
117 static FormatEntity::Entry::Definition g_module_child_entries[] =
119 ENTRY_CHILDREN("file", ModuleFile, None, g_file_child_entries),
122 static FormatEntity::Entry::Definition g_process_child_entries[] =
124 ENTRY ( "id" , ProcessID , UInt64 ),
125 ENTRY_VALUE ( "name" , ProcessFile , CString , FileKind::Basename),
126 ENTRY_CHILDREN ( "file" , ProcessFile , None , g_file_child_entries),
129 static FormatEntity::Entry::Definition g_svar_child_entries[] =
131 ENTRY ( "*" , ParentString , None)
134 static FormatEntity::Entry::Definition g_var_child_entries[] =
136 ENTRY ( "*" , ParentString , None)
139 static FormatEntity::Entry::Definition g_thread_child_entries[] =
141 ENTRY ( "id" , ThreadID , UInt64 ),
142 ENTRY ( "protocol_id" , ThreadProtocolID , UInt64 ),
143 ENTRY ( "index" , ThreadIndexID , UInt32 ),
144 ENTRY_CHILDREN ( "info" , ThreadInfo , None , g_string_entry),
145 ENTRY ( "queue" , ThreadQueue , CString ),
146 ENTRY ( "name" , ThreadName , CString ),
147 ENTRY ( "stop-reason" , ThreadStopReason , CString ),
148 ENTRY ( "return-value" , ThreadReturnValue , CString ),
149 ENTRY ( "completed-expression", ThreadCompletedExpression , CString ),
152 static FormatEntity::Entry::Definition g_target_child_entries[] =
154 ENTRY ( "arch" , TargetArch , CString ),
157 #define _TO_STR2(_val) #_val
158 #define _TO_STR(_val) _TO_STR2(_val)
160 static FormatEntity::Entry::Definition g_ansi_fg_entries[] =
162 ENTRY_STRING ("black" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLACK) ANSI_ESC_END),
163 ENTRY_STRING ("red" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_RED) ANSI_ESC_END),
164 ENTRY_STRING ("green" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_GREEN) ANSI_ESC_END),
165 ENTRY_STRING ("yellow" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_YELLOW) ANSI_ESC_END),
166 ENTRY_STRING ("blue" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BLUE) ANSI_ESC_END),
167 ENTRY_STRING ("purple" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_PURPLE) ANSI_ESC_END),
168 ENTRY_STRING ("cyan" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_CYAN) ANSI_ESC_END),
169 ENTRY_STRING ("white" , ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_WHITE) ANSI_ESC_END),
172 static FormatEntity::Entry::Definition g_ansi_bg_entries[] =
174 ENTRY_STRING ("black" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLACK) ANSI_ESC_END),
175 ENTRY_STRING ("red" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_RED) ANSI_ESC_END),
176 ENTRY_STRING ("green" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_GREEN) ANSI_ESC_END),
177 ENTRY_STRING ("yellow" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_YELLOW) ANSI_ESC_END),
178 ENTRY_STRING ("blue" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLUE) ANSI_ESC_END),
179 ENTRY_STRING ("purple" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_PURPLE) ANSI_ESC_END),
180 ENTRY_STRING ("cyan" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_CYAN) ANSI_ESC_END),
181 ENTRY_STRING ("white" , ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_WHITE) ANSI_ESC_END),
184 static FormatEntity::Entry::Definition g_ansi_entries[] =
186 ENTRY_CHILDREN ( "fg" , Invalid , None , g_ansi_fg_entries),
187 ENTRY_CHILDREN ( "bg" , Invalid , None , g_ansi_bg_entries),
188 ENTRY_STRING ( "normal" , ANSI_ESC_START _TO_STR(ANSI_CTRL_NORMAL) ANSI_ESC_END),
189 ENTRY_STRING ( "bold" , ANSI_ESC_START _TO_STR(ANSI_CTRL_BOLD) ANSI_ESC_END),
190 ENTRY_STRING ( "faint" , ANSI_ESC_START _TO_STR(ANSI_CTRL_FAINT) ANSI_ESC_END),
191 ENTRY_STRING ( "italic" , ANSI_ESC_START _TO_STR(ANSI_CTRL_ITALIC) ANSI_ESC_END),
192 ENTRY_STRING ( "underline" , ANSI_ESC_START _TO_STR(ANSI_CTRL_UNDERLINE) ANSI_ESC_END),
193 ENTRY_STRING ( "slow-blink" , ANSI_ESC_START _TO_STR(ANSI_CTRL_SLOW_BLINK) ANSI_ESC_END),
194 ENTRY_STRING ( "fast-blink" , ANSI_ESC_START _TO_STR(ANSI_CTRL_FAST_BLINK) ANSI_ESC_END),
195 ENTRY_STRING ( "negative" , ANSI_ESC_START _TO_STR(ANSI_CTRL_IMAGE_NEGATIVE) ANSI_ESC_END),
196 ENTRY_STRING ( "conceal" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CONCEAL) ANSI_ESC_END),
197 ENTRY_STRING ( "crossed-out" , ANSI_ESC_START _TO_STR(ANSI_CTRL_CROSSED_OUT) ANSI_ESC_END),
200 static FormatEntity::Entry::Definition g_script_child_entries[] =
202 ENTRY ( "frame" , ScriptFrame , None),
203 ENTRY ( "process" , ScriptProcess , None),
204 ENTRY ( "target" , ScriptTarget , None),
205 ENTRY ( "thread" , ScriptThread , None),
206 ENTRY ( "var" , ScriptVariable , None),
207 ENTRY ( "svar" , ScriptVariableSynthetic , None),
208 ENTRY ( "thread" , ScriptThread , None),
211 static FormatEntity::Entry::Definition g_top_level_entries[] =
213 ENTRY_CHILDREN ("addr" , AddressLoadOrFile , UInt64 , g_addr_entries),
214 ENTRY ("addr-file-or-load" , AddressLoadOrFile , UInt64 ),
215 ENTRY_CHILDREN ("ansi" , Invalid , None , g_ansi_entries),
216 ENTRY ("current-pc-arrow" , CurrentPCArrow , CString ),
217 ENTRY_CHILDREN ("file" , File , CString , g_file_child_entries),
218 ENTRY ("language" , Lang , CString),
219 ENTRY_CHILDREN ("frame" , Invalid , None , g_frame_child_entries),
220 ENTRY_CHILDREN ("function" , Invalid , None , g_function_child_entries),
221 ENTRY_CHILDREN ("line" , Invalid , None , g_line_child_entries),
222 ENTRY_CHILDREN ("module" , Invalid , None , g_module_child_entries),
223 ENTRY_CHILDREN ("process" , Invalid , None , g_process_child_entries),
224 ENTRY_CHILDREN ("script" , Invalid , None , g_script_child_entries),
225 ENTRY_CHILDREN_KEEP_SEP ("svar" , VariableSynthetic , None , g_svar_child_entries),
226 ENTRY_CHILDREN ("thread" , Invalid , None , g_thread_child_entries),
227 ENTRY_CHILDREN ("target" , Invalid , None , g_target_child_entries),
228 ENTRY_CHILDREN_KEEP_SEP ("var" , Variable , None , g_var_child_entries),
231 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));
282 FormatEntity::Parse (const llvm::StringRef &format_str, Entry &entry)
285 entry.type = Entry::Type::Root;
286 llvm::StringRef modifiable_format (format_str);
287 return ParseInternal (modifiable_format, entry, 0);
290 #define ENUM_TO_CSTR(eee) case FormatEntity::Entry::Type::eee: return #eee
293 FormatEntity::Entry::TypeToCString (Type t)
297 ENUM_TO_CSTR(Invalid);
298 ENUM_TO_CSTR(ParentNumber);
299 ENUM_TO_CSTR(ParentString);
300 ENUM_TO_CSTR(InsertString);
302 ENUM_TO_CSTR(String);
304 ENUM_TO_CSTR(Variable);
305 ENUM_TO_CSTR(VariableSynthetic);
306 ENUM_TO_CSTR(ScriptVariable);
307 ENUM_TO_CSTR(ScriptVariableSynthetic);
308 ENUM_TO_CSTR(AddressLoad);
309 ENUM_TO_CSTR(AddressFile);
310 ENUM_TO_CSTR(AddressLoadOrFile);
311 ENUM_TO_CSTR(ProcessID);
312 ENUM_TO_CSTR(ProcessFile);
313 ENUM_TO_CSTR(ScriptProcess);
314 ENUM_TO_CSTR(ThreadID);
315 ENUM_TO_CSTR(ThreadProtocolID);
316 ENUM_TO_CSTR(ThreadIndexID);
317 ENUM_TO_CSTR(ThreadName);
318 ENUM_TO_CSTR(ThreadQueue);
319 ENUM_TO_CSTR(ThreadStopReason);
320 ENUM_TO_CSTR(ThreadReturnValue);
321 ENUM_TO_CSTR(ThreadCompletedExpression);
322 ENUM_TO_CSTR(ScriptThread);
323 ENUM_TO_CSTR(ThreadInfo);
324 ENUM_TO_CSTR(TargetArch);
325 ENUM_TO_CSTR(ScriptTarget);
326 ENUM_TO_CSTR(ModuleFile);
329 ENUM_TO_CSTR(FrameIndex);
330 ENUM_TO_CSTR(FrameRegisterPC);
331 ENUM_TO_CSTR(FrameRegisterSP);
332 ENUM_TO_CSTR(FrameRegisterFP);
333 ENUM_TO_CSTR(FrameRegisterFlags);
334 ENUM_TO_CSTR(FrameRegisterByName);
335 ENUM_TO_CSTR(ScriptFrame);
336 ENUM_TO_CSTR(FunctionID);
337 ENUM_TO_CSTR(FunctionDidChange);
338 ENUM_TO_CSTR(FunctionInitialFunction);
339 ENUM_TO_CSTR(FunctionName);
340 ENUM_TO_CSTR(FunctionNameWithArgs);
341 ENUM_TO_CSTR(FunctionNameNoArgs);
342 ENUM_TO_CSTR(FunctionAddrOffset);
343 ENUM_TO_CSTR(FunctionAddrOffsetConcrete);
344 ENUM_TO_CSTR(FunctionLineOffset);
345 ENUM_TO_CSTR(FunctionPCOffset);
346 ENUM_TO_CSTR(FunctionInitial);
347 ENUM_TO_CSTR(FunctionChanged);
348 ENUM_TO_CSTR(FunctionIsOptimized);
349 ENUM_TO_CSTR(LineEntryFile);
350 ENUM_TO_CSTR(LineEntryLineNumber);
351 ENUM_TO_CSTR(LineEntryStartAddress);
352 ENUM_TO_CSTR(LineEntryEndAddress);
353 ENUM_TO_CSTR(CurrentPCArrow);
361 FormatEntity::Entry::Dump (Stream &s, int depth) const
363 s.Printf ("%*.*s%-20s: ", depth * 2, depth * 2, "", TypeToCString(type));
364 if (fmt != eFormatDefault)
365 s.Printf ("lldb-format = %s, ", FormatManager::GetFormatAsCString (fmt));
367 s.Printf ("string = \"%s\"", string.c_str());
368 if (!printf_format.empty())
369 s.Printf ("printf_format = \"%s\"", printf_format.c_str());
371 s.Printf ("number = %" PRIu64 " (0x%" PRIx64 "), ", number, number);
373 s.Printf ("deref = true, ");
375 for (const auto &child : children)
377 child.Dump(s, depth + 1);
381 template <typename T>
382 static bool RunScriptFormatKeyword(Stream &s,
383 const SymbolContext *sc,
384 const ExecutionContext *exe_ctx,
386 const char *script_function_name)
388 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
392 ScriptInterpreter *script_interpreter = target->GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
393 if (script_interpreter)
396 std::string script_output;
398 if (script_interpreter->RunScriptFormatKeyword(script_function_name, t, script_output, error) && error.Success())
400 s.Printf("%s", script_output.c_str());
405 s.Printf("<error: %s>",error.AsCString());
413 DumpAddress (Stream &s,
414 const SymbolContext *sc,
415 const ExecutionContext *exe_ctx,
417 bool print_file_addr_or_load_addr)
419 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
420 addr_t vaddr = LLDB_INVALID_ADDRESS;
421 if (exe_ctx && !target->GetSectionLoadList().IsEmpty())
422 vaddr = addr.GetLoadAddress (target);
423 if (vaddr == LLDB_INVALID_ADDRESS)
424 vaddr = addr.GetFileAddress ();
426 if (vaddr != LLDB_INVALID_ADDRESS)
429 if (exe_ctx && target)
431 addr_width = target->GetArchitecture().GetAddressByteSize() * 2;
435 if (print_file_addr_or_load_addr)
437 ExecutionContextScope *exe_scope = nullptr;
439 exe_scope = exe_ctx->GetBestExecutionContextScope();
440 addr.Dump (&s, exe_scope, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, 0);
444 s.Printf("0x%*.*" PRIx64, addr_width, addr_width, vaddr);
452 DumpAddressOffsetFromFunction (Stream &s,
453 const SymbolContext *sc,
454 const ExecutionContext *exe_ctx,
455 const Address &format_addr,
458 bool print_zero_offsets)
460 if (format_addr.IsValid())
468 func_addr = sc->function->GetAddressRange().GetBaseAddress();
469 if (sc->block && !concrete_only)
471 // Check to make sure we aren't in an inline
472 // function. If we are, use the inline block
473 // range that contains "format_addr" since
474 // blocks can be discontiguous.
475 Block *inline_block = sc->block->GetContainingInlinedBlock ();
476 AddressRange inline_range;
477 if (inline_block && inline_block->GetRangeContainingAddress (format_addr, inline_range))
478 func_addr = inline_range.GetBaseAddress();
481 else if (sc->symbol && sc->symbol->ValueIsAddress())
482 func_addr = sc->symbol->GetAddressRef();
485 if (func_addr.IsValid())
487 const char *addr_offset_padding = no_padding ? "" : " ";
489 if (func_addr.GetSection() == format_addr.GetSection())
491 addr_t func_file_addr = func_addr.GetFileAddress();
492 addr_t addr_file_addr = format_addr.GetFileAddress();
493 if (addr_file_addr > func_file_addr
494 || (addr_file_addr == func_file_addr && print_zero_offsets))
496 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_file_addr - func_file_addr);
498 else if (addr_file_addr < func_file_addr)
500 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_file_addr - addr_file_addr);
506 Target *target = Target::GetTargetFromContexts (exe_ctx, sc);
509 addr_t func_load_addr = func_addr.GetLoadAddress (target);
510 addr_t addr_load_addr = format_addr.GetLoadAddress (target);
511 if (addr_load_addr > func_load_addr
512 || (addr_load_addr == func_load_addr && print_zero_offsets))
514 s.Printf("%s+%s%" PRIu64, addr_offset_padding, addr_offset_padding, addr_load_addr - func_load_addr);
516 else if (addr_load_addr < func_load_addr)
518 s.Printf("%s-%s%" PRIu64, addr_offset_padding, addr_offset_padding, func_load_addr - addr_load_addr);
529 ScanBracketedRange (llvm::StringRef subpath,
530 size_t& close_bracket_index,
531 const char*& var_name_final_if_array_range,
532 int64_t& index_lower,
533 int64_t& index_higher)
535 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
536 close_bracket_index = llvm::StringRef::npos;
537 const size_t open_bracket_index = subpath.find('[');
538 if (open_bracket_index == llvm::StringRef::npos)
541 log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely");
545 close_bracket_index = subpath.find(']', open_bracket_index + 1);
547 if (close_bracket_index == llvm::StringRef::npos)
550 log->Printf("[ScanBracketedRange] no bracketed range, skipping entirely");
555 var_name_final_if_array_range = subpath.data() + open_bracket_index;
557 if (close_bracket_index - open_bracket_index == 1)
560 log->Printf("[ScanBracketedRange] '[]' detected.. going from 0 to end of data");
565 const size_t separator_index = subpath.find('-', open_bracket_index + 1);
567 if (separator_index == llvm::StringRef::npos)
569 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
570 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
571 index_higher = index_lower;
573 log->Printf("[ScanBracketedRange] [%" PRId64 "] detected, high index is same", index_lower);
577 const char *index_lower_cstr = subpath.data() + open_bracket_index + 1;
578 const char *index_higher_cstr = subpath.data() + separator_index + 1;
579 index_lower = ::strtoul(index_lower_cstr, nullptr, 0);
580 index_higher = ::strtoul(index_higher_cstr, nullptr, 0);
582 log->Printf("[ScanBracketedRange] [%" PRId64 "-%" PRId64 "] detected", index_lower, index_higher);
584 if (index_lower > index_higher && index_higher > 0)
587 log->Printf("[ScanBracketedRange] swapping indices");
588 const int64_t temp = index_lower;
589 index_lower = index_higher;
598 DumpFile (Stream &s, const FileSpec &file, FileKind file_kind)
602 case FileKind::FileError:
605 case FileKind::Basename:
606 if (file.GetFilename())
608 s << file.GetFilename();
613 case FileKind::Dirname:
614 if (file.GetDirectory())
616 s << file.GetDirectory();
621 case FileKind::Fullpath:
633 DumpRegister (Stream &s,
635 RegisterKind reg_kind,
642 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
646 const uint32_t lldb_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber(reg_kind, reg_num);
647 if (lldb_reg_num != LLDB_INVALID_REGNUM)
649 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (lldb_reg_num);
652 RegisterValue reg_value;
653 if (reg_ctx->ReadRegister (reg_info, reg_value))
655 reg_value.Dump(&s, reg_info, false, false, format);
666 ExpandIndexedExpression (ValueObject* valobj,
671 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
672 const char* ptr_deref_format = "[%d]";
673 std::string ptr_deref_buffer(10,0);
674 ::sprintf(&ptr_deref_buffer[0], ptr_deref_format, index);
676 log->Printf("[ExpandIndexedExpression] name to deref: %s",ptr_deref_buffer.c_str());
677 const char* first_unparsed;
678 ValueObject::GetValueForExpressionPathOptions options;
679 ValueObject::ExpressionPathEndResultType final_value_type;
680 ValueObject::ExpressionPathScanEndReason reason_to_stop;
681 ValueObject::ExpressionPathAftermath what_next = (deref_pointer ? ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
682 ValueObjectSP item = valobj->GetValueForExpressionPath (ptr_deref_buffer.c_str(),
691 log->Printf("[ExpandIndexedExpression] ERROR: unparsed portion = %s, why stopping = %d,"
692 " final_value_type %d",
693 first_unparsed, reason_to_stop, final_value_type);
698 log->Printf("[ExpandIndexedExpression] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
699 " final_value_type %d",
700 first_unparsed, reason_to_stop, final_value_type);
706 ConvertValueObjectStyleToChar(ValueObject::ValueObjectRepresentationStyle style)
710 case ValueObject::eValueObjectRepresentationStyleLanguageSpecific: return '@';
711 case ValueObject::eValueObjectRepresentationStyleValue: return 'V';
712 case ValueObject::eValueObjectRepresentationStyleLocation: return 'L';
713 case ValueObject::eValueObjectRepresentationStyleSummary: return 'S';
714 case ValueObject::eValueObjectRepresentationStyleChildrenCount: return '#';
715 case ValueObject::eValueObjectRepresentationStyleType: return 'T';
716 case ValueObject::eValueObjectRepresentationStyleName: return 'N';
717 case ValueObject::eValueObjectRepresentationStyleExpressionPath: return '>';
723 DumpValue (Stream &s,
724 const SymbolContext *sc,
725 const ExecutionContext *exe_ctx,
726 const FormatEntity::Entry &entry,
729 if (valobj == nullptr)
732 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
733 Format custom_format = eFormatInvalid;
734 ValueObject::ValueObjectRepresentationStyle val_obj_display = entry.string.empty() ? ValueObject::eValueObjectRepresentationStyleValue : ValueObject::eValueObjectRepresentationStyleSummary;
736 bool do_deref_pointer = entry.deref;
737 bool is_script = false;
740 case FormatEntity::Entry::Type::ScriptVariable:
744 case FormatEntity::Entry::Type::Variable:
745 custom_format = entry.fmt;
746 val_obj_display = (ValueObject::ValueObjectRepresentationStyle)entry.number;
749 case FormatEntity::Entry::Type::ScriptVariableSynthetic:
752 case FormatEntity::Entry::Type::VariableSynthetic:
753 custom_format = entry.fmt;
754 val_obj_display = (ValueObject::ValueObjectRepresentationStyle)entry.number;
755 if (!valobj->IsSynthetic())
757 valobj = valobj->GetSyntheticValue().get();
758 if (valobj == nullptr)
767 if (valobj == nullptr)
770 ValueObject::ExpressionPathAftermath what_next = (do_deref_pointer ?
771 ValueObject::eExpressionPathAftermathDereference : ValueObject::eExpressionPathAftermathNothing);
772 ValueObject::GetValueForExpressionPathOptions options;
773 options.DontCheckDotVsArrowSyntax().DoAllowBitfieldSyntax().DoAllowFragileIVar().SetSyntheticChildrenTraversal(ValueObject::GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both);
774 ValueObject* target = nullptr;
775 const char* var_name_final_if_array_range = nullptr;
776 size_t close_bracket_index = llvm::StringRef::npos;
777 int64_t index_lower = -1;
778 int64_t index_higher = -1;
779 bool is_array_range = false;
780 const char* first_unparsed;
781 bool was_plain_var = false;
782 bool was_var_format = false;
783 bool was_var_indexed = false;
784 ValueObject::ExpressionPathScanEndReason reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
785 ValueObject::ExpressionPathEndResultType final_value_type = ValueObject::eExpressionPathEndResultTypePlain;
789 return RunScriptFormatKeyword (s, sc, exe_ctx, valobj, entry.string.c_str());
792 llvm::StringRef subpath (entry.string);
793 // simplest case ${var}, just print valobj's value
794 if (entry.string.empty())
796 if (entry.printf_format.empty() && entry.fmt == eFormatDefault && entry.number == ValueObject::eValueObjectRepresentationStyleValue)
797 was_plain_var = true;
799 was_var_format = true;
802 else // this is ${var.something} or multiple .something nested
804 if (entry.string[0] == '[')
805 was_var_indexed = true;
806 ScanBracketedRange (subpath,
808 var_name_final_if_array_range,
814 const std::string &expr_path = entry.string;
817 log->Printf("[Debugger::FormatPrompt] symbol to expand: %s",expr_path.c_str());
819 target = valobj->GetValueForExpressionPath(expr_path.c_str(),
829 log->Printf("[Debugger::FormatPrompt] ERROR: unparsed portion = %s, why stopping = %d,"
830 " final_value_type %d",
831 first_unparsed, reason_to_stop, final_value_type);
837 log->Printf("[Debugger::FormatPrompt] ALL RIGHT: unparsed portion = %s, why stopping = %d,"
838 " final_value_type %d",
839 first_unparsed, reason_to_stop, final_value_type);
840 target = target->GetQualifiedRepresentationIfAvailable(target->GetDynamicValueType(), true).get();
844 is_array_range = (final_value_type == ValueObject::eExpressionPathEndResultTypeBoundedRange ||
845 final_value_type == ValueObject::eExpressionPathEndResultTypeUnboundedRange);
847 do_deref_pointer = (what_next == ValueObject::eExpressionPathAftermathDereference);
849 if (do_deref_pointer && !is_array_range)
851 // I have not deref-ed yet, let's do it
852 // this happens when we are not going through GetValueForVariableExpressionPath
853 // to get to the target ValueObject
855 target = target->Dereference(error).get();
859 log->Printf("[Debugger::FormatPrompt] ERROR: %s\n", error.AsCString("unknown")); \
862 do_deref_pointer = false;
868 log->Printf("[Debugger::FormatPrompt] could not calculate target for prompt expression");
872 // we do not want to use the summary for a bitfield of type T:n
873 // if we were originally dealing with just a T - that would get
874 // us into an endless recursion
875 if (target->IsBitfield() && was_var_indexed)
877 // TODO: check for a (T:n)-specific summary - we should still obey that
878 StreamString bitfield_name;
879 bitfield_name.Printf("%s:%d", target->GetTypeName().AsCString(), target->GetBitfieldBitSize());
880 lldb::TypeNameSpecifierImplSP type_sp(new TypeNameSpecifierImpl(bitfield_name.GetData(),false));
881 if (val_obj_display == ValueObject::eValueObjectRepresentationStyleSummary && !DataVisualization::GetSummaryForType(type_sp))
882 val_obj_display = ValueObject::eValueObjectRepresentationStyleValue;
885 // TODO use flags for these
886 const uint32_t type_info_flags = target->GetCompilerType().GetTypeInfo(nullptr);
887 bool is_array = (type_info_flags & eTypeIsArray) != 0;
888 bool is_pointer = (type_info_flags & eTypeIsPointer) != 0;
889 bool is_aggregate = target->GetCompilerType().IsAggregateType();
891 if ((is_array || is_pointer) && (!is_array_range) && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) // this should be wrong, but there are some exceptions
893 StreamString str_temp;
895 log->Printf("[Debugger::FormatPrompt] I am into array || pointer && !range");
897 if (target->HasSpecialPrintableRepresentation(val_obj_display, custom_format))
899 // try to use the special cases
900 bool success = target->DumpPrintableRepresentation(str_temp,
904 log->Printf("[Debugger::FormatPrompt] special cases did%s match", success ? "" : "n't");
908 s << str_temp.GetData();
913 if (was_plain_var) // if ${var}
915 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
917 else if (is_pointer) // if pointer, value is the address stored
919 target->DumpPrintableRepresentation (s,
922 ValueObject::ePrintableRepresentationSpecialCasesDisable);
928 // if directly trying to print ${var}, and this is an aggregate, display a nice
929 // type @ location message
930 if (is_aggregate && was_plain_var)
932 s << target->GetTypeName() << " @ " << target->GetLocationAsCString();
936 // if directly trying to print ${var%V}, and this is an aggregate, do not let the user do it
937 if (is_aggregate && ((was_var_format && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)))
939 s << "<invalid use of aggregate type>";
946 log->Printf("[Debugger::FormatPrompt] dumping ordinary printable output");
947 return target->DumpPrintableRepresentation(s,val_obj_display, custom_format);
952 log->Printf("[Debugger::FormatPrompt] checking if I can handle as array");
953 if (!is_array && !is_pointer)
956 log->Printf("[Debugger::FormatPrompt] handle as array");
957 StreamString special_directions_stream;
958 llvm::StringRef special_directions;
959 if (close_bracket_index != llvm::StringRef::npos && subpath.size() > close_bracket_index)
961 ConstString additional_data (subpath.drop_front(close_bracket_index+1));
962 special_directions_stream.Printf("${%svar%s",
963 do_deref_pointer ? "*" : "",
964 additional_data.GetCString());
966 if (entry.fmt != eFormatDefault)
968 const char format_char = FormatManager::GetFormatAsFormatChar(entry.fmt);
969 if (format_char != '\0')
970 special_directions_stream.Printf("%%%c", format_char);
973 const char *format_cstr = FormatManager::GetFormatAsCString(entry.fmt);
974 special_directions_stream.Printf("%%%s", format_cstr);
977 else if (entry.number != 0)
979 const char style_char = ConvertValueObjectStyleToChar ((ValueObject::ValueObjectRepresentationStyle)entry.number);
981 special_directions_stream.Printf("%%%c", style_char);
983 special_directions_stream.PutChar('}');
984 special_directions = llvm::StringRef(special_directions_stream.GetString());
987 // let us display items index_lower thru index_higher of this array
990 if (index_higher < 0)
991 index_higher = valobj->GetNumChildren() - 1;
993 uint32_t max_num_children = target->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
996 for (int64_t index = index_lower;index<=index_higher; ++index)
998 ValueObject* item = ExpandIndexedExpression (target,
1000 exe_ctx->GetFramePtr(),
1006 log->Printf("[Debugger::FormatPrompt] ERROR in getting child item at index %" PRId64, index);
1011 log->Printf("[Debugger::FormatPrompt] special_directions for child item: %s",special_directions.data() ? special_directions.data() : "");
1014 if (special_directions.empty())
1016 success &= item->DumpPrintableRepresentation(s,val_obj_display, custom_format);
1020 success &= FormatEntity::FormatStringRef(special_directions, s, sc, exe_ctx, nullptr, item, false, false);
1023 if (--max_num_children == 0)
1025 s.PutCString(", ...");
1029 if (index < index_higher)
1038 DumpRegister (Stream &s,
1040 const char *reg_name,
1045 RegisterContext *reg_ctx = frame->GetRegisterContext().get();
1049 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(reg_name);
1052 RegisterValue reg_value;
1053 if (reg_ctx->ReadRegister (reg_info, reg_value))
1055 reg_value.Dump(&s, reg_info, false, false, format);
1065 FormatThreadExtendedInfoRecurse(const FormatEntity::Entry &entry,
1066 const StructuredData::ObjectSP &thread_info_dictionary,
1067 const SymbolContext *sc,
1068 const ExecutionContext *exe_ctx,
1071 llvm::StringRef path(entry.string);
1073 StructuredData::ObjectSP value = thread_info_dictionary->GetObjectForDotSeparatedPath (path);
1077 if (value->GetType() == StructuredData::Type::eTypeInteger)
1079 const char *token_format = "0x%4.4" PRIx64;
1080 if (!entry.printf_format.empty())
1081 token_format = entry.printf_format.c_str();
1082 s.Printf(token_format, value->GetAsInteger()->GetValue());
1085 else if (value->GetType() == StructuredData::Type::eTypeFloat)
1087 s.Printf ("%f", value->GetAsFloat()->GetValue());
1090 else if (value->GetType() == StructuredData::Type::eTypeString)
1092 s.Printf("%s", value->GetAsString()->GetValue().c_str());
1095 else if (value->GetType() == StructuredData::Type::eTypeArray)
1097 if (value->GetAsArray()->GetSize() > 0)
1099 s.Printf ("%zu", value->GetAsArray()->GetSize());
1103 else if (value->GetType() == StructuredData::Type::eTypeDictionary)
1105 s.Printf ("%zu", value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize());
1114 IsToken(const char *var_name_begin, const char *var)
1116 return (::strncmp (var_name_begin, var, strlen(var)) == 0);
1120 FormatEntity::FormatStringRef (const llvm::StringRef &format_str,
1122 const SymbolContext *sc,
1123 const ExecutionContext *exe_ctx,
1124 const Address *addr,
1125 ValueObject* valobj,
1126 bool function_changed,
1127 bool initial_function)
1129 if (!format_str.empty())
1131 FormatEntity::Entry root;
1132 Error error = FormatEntity::Parse(format_str, root);
1133 if (error.Success())
1135 return FormatEntity::Format (root,
1149 FormatEntity::FormatCString (const char *format,
1151 const SymbolContext *sc,
1152 const ExecutionContext *exe_ctx,
1153 const Address *addr,
1154 ValueObject* valobj,
1155 bool function_changed,
1156 bool initial_function)
1158 if (format && format[0])
1160 FormatEntity::Entry root;
1161 llvm::StringRef format_str(format);
1162 Error error = FormatEntity::Parse(format_str, root);
1163 if (error.Success())
1165 return FormatEntity::Format (root,
1179 FormatEntity::Format (const Entry &entry,
1181 const SymbolContext *sc,
1182 const ExecutionContext *exe_ctx,
1183 const Address *addr,
1184 ValueObject* valobj,
1185 bool function_changed,
1186 bool initial_function)
1190 case Entry::Type::Invalid:
1191 case Entry::Type::ParentNumber: // Only used for FormatEntity::Entry::Definition encoding
1192 case Entry::Type::ParentString: // Only used for FormatEntity::Entry::Definition encoding
1193 case Entry::Type::InsertString: // Only used for FormatEntity::Entry::Definition encoding
1196 case Entry::Type::Root:
1197 for (const auto &child : entry.children)
1208 return false; // If any item of root fails, then the formatting fails
1211 return true; // Only return true if all items succeeded
1213 case Entry::Type::String:
1214 s.PutCString(entry.string.c_str());
1217 case Entry::Type::Scope:
1219 StreamString scope_stream;
1220 bool success = false;
1221 for (const auto &child : entry.children)
1223 success = Format (child, scope_stream, sc, exe_ctx, addr, valobj, function_changed, initial_function);
1227 // Only if all items in a scope succeed, then do we
1228 // print the output into the main stream
1230 s.Write(scope_stream.GetString().data(), scope_stream.GetString().size());
1232 return true; // Scopes always successfully print themselves
1234 case Entry::Type::Variable:
1235 case Entry::Type::VariableSynthetic:
1236 case Entry::Type::ScriptVariable:
1237 case Entry::Type::ScriptVariableSynthetic:
1238 return DumpValue(s, sc, exe_ctx, entry, valobj);
1240 case Entry::Type::AddressFile:
1241 case Entry::Type::AddressLoad:
1242 case Entry::Type::AddressLoadOrFile:
1243 return (addr != nullptr && addr->IsValid() &&
1244 DumpAddress(s, sc, exe_ctx, *addr, entry.type == Entry::Type::AddressLoadOrFile));
1246 case Entry::Type::ProcessID:
1249 Process *process = exe_ctx->GetProcessPtr();
1252 const char *format = "%" PRIu64;
1253 if (!entry.printf_format.empty())
1254 format = entry.printf_format.c_str();
1255 s.Printf(format, process->GetID());
1261 case Entry::Type::ProcessFile:
1264 Process *process = exe_ctx->GetProcessPtr();
1267 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
1270 if (DumpFile(s, exe_module->GetFileSpec(), (FileKind)entry.number))
1277 case Entry::Type::ScriptProcess:
1280 Process *process = exe_ctx->GetProcessPtr();
1282 return RunScriptFormatKeyword (s, sc, exe_ctx, process, entry.string.c_str());
1286 case Entry::Type::ThreadID:
1289 Thread *thread = exe_ctx->GetThreadPtr();
1292 const char *format = "0x%4.4" PRIx64;
1293 if (!entry.printf_format.empty())
1295 // Watch for the special "tid" format...
1296 if (entry.printf_format == "tid")
1298 // TODO(zturner): Rather than hardcoding this to be platform specific, it should be controlled by a
1299 // setting and the default value of the setting can be different depending on the platform.
1300 Target &target = thread->GetProcess()->GetTarget();
1301 ArchSpec arch (target.GetArchitecture ());
1302 llvm::Triple::OSType ostype = arch.IsValid() ? arch.GetTriple().getOS() : llvm::Triple::UnknownOS;
1303 if ((ostype == llvm::Triple::FreeBSD) || (ostype == llvm::Triple::Linux))
1305 format = "%" PRIu64;
1310 format = entry.printf_format.c_str();
1313 s.Printf(format, thread->GetID());
1319 case Entry::Type::ThreadProtocolID:
1322 Thread *thread = exe_ctx->GetThreadPtr();
1325 const char *format = "0x%4.4" PRIx64;
1326 if (!entry.printf_format.empty())
1327 format = entry.printf_format.c_str();
1328 s.Printf(format, thread->GetProtocolID());
1334 case Entry::Type::ThreadIndexID:
1337 Thread *thread = exe_ctx->GetThreadPtr();
1340 const char *format = "%" PRIu32;
1341 if (!entry.printf_format.empty())
1342 format = entry.printf_format.c_str();
1343 s.Printf(format, thread->GetIndexID());
1349 case Entry::Type::ThreadName:
1352 Thread *thread = exe_ctx->GetThreadPtr();
1355 const char *cstr = thread->GetName();
1356 if (cstr && cstr[0])
1365 case Entry::Type::ThreadQueue:
1368 Thread *thread = exe_ctx->GetThreadPtr();
1371 const char *cstr = thread->GetQueueName();
1372 if (cstr && cstr[0])
1381 case Entry::Type::ThreadStopReason:
1384 Thread *thread = exe_ctx->GetThreadPtr();
1387 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1388 if (stop_info_sp && stop_info_sp->IsValid())
1390 const char *cstr = stop_info_sp->GetDescription();
1391 if (cstr && cstr[0])
1401 case Entry::Type::ThreadReturnValue:
1404 Thread *thread = exe_ctx->GetThreadPtr();
1407 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1408 if (stop_info_sp && stop_info_sp->IsValid())
1410 ValueObjectSP return_valobj_sp = StopInfo::GetReturnValueObject (stop_info_sp);
1411 if (return_valobj_sp)
1413 return_valobj_sp->Dump(s);
1421 case Entry::Type::ThreadCompletedExpression:
1424 Thread *thread = exe_ctx->GetThreadPtr();
1427 StopInfoSP stop_info_sp = thread->GetStopInfo ();
1428 if (stop_info_sp && stop_info_sp->IsValid())
1430 ExpressionVariableSP expression_var_sp = StopInfo::GetExpressionVariable (stop_info_sp);
1431 if (expression_var_sp && expression_var_sp->GetValueObject())
1433 expression_var_sp->GetValueObject()->Dump(s);
1441 case Entry::Type::ScriptThread:
1444 Thread *thread = exe_ctx->GetThreadPtr();
1446 return RunScriptFormatKeyword (s, sc, exe_ctx, thread, entry.string.c_str());
1450 case Entry::Type::ThreadInfo:
1453 Thread *thread = exe_ctx->GetThreadPtr();
1456 StructuredData::ObjectSP object_sp = thread->GetExtendedInfo();
1457 if (object_sp && object_sp->GetType() == StructuredData::Type::eTypeDictionary)
1459 if (FormatThreadExtendedInfoRecurse (entry, object_sp, sc, exe_ctx, s))
1466 case Entry::Type::TargetArch:
1469 Target *target = exe_ctx->GetTargetPtr();
1472 const ArchSpec &arch = target->GetArchitecture ();
1475 s.PutCString (arch.GetArchitectureName());
1482 case Entry::Type::ScriptTarget:
1485 Target *target = exe_ctx->GetTargetPtr();
1487 return RunScriptFormatKeyword (s, sc, exe_ctx, target, entry.string.c_str());
1491 case Entry::Type::ModuleFile:
1494 Module *module = sc->module_sp.get();
1497 if (DumpFile(s, module->GetFileSpec(), (FileKind)entry.number))
1503 case Entry::Type::File:
1506 CompileUnit *cu = sc->comp_unit;
1509 // CompileUnit is a FileSpec
1510 if (DumpFile(s, *cu, (FileKind)entry.number))
1516 case Entry::Type::Lang:
1519 CompileUnit *cu = sc->comp_unit;
1522 const char *lang_name = Language::GetNameForLanguageType(cu->GetLanguage());
1525 s.PutCString(lang_name);
1532 case Entry::Type::FrameIndex:
1535 StackFrame *frame = exe_ctx->GetFramePtr();
1538 const char *format = "%" PRIu32;
1539 if (!entry.printf_format.empty())
1540 format = entry.printf_format.c_str();
1541 s.Printf(format, frame->GetFrameIndex());
1547 case Entry::Type::FrameRegisterPC:
1550 StackFrame *frame = exe_ctx->GetFramePtr();
1553 const Address &pc_addr = frame->GetFrameCodeAddress();
1554 if (pc_addr.IsValid())
1556 if (DumpAddress(s, sc, exe_ctx, pc_addr, false))
1563 case Entry::Type::FrameRegisterSP:
1566 StackFrame *frame = exe_ctx->GetFramePtr();
1569 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, (lldb::Format)entry.number))
1575 case Entry::Type::FrameRegisterFP:
1578 StackFrame *frame = exe_ctx->GetFramePtr();
1581 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FP, (lldb::Format)entry.number))
1587 case Entry::Type::FrameRegisterFlags:
1590 StackFrame *frame = exe_ctx->GetFramePtr();
1593 if (DumpRegister (s, frame, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, (lldb::Format)entry.number))
1599 case Entry::Type::FrameRegisterByName:
1602 StackFrame *frame = exe_ctx->GetFramePtr();
1605 if (DumpRegister (s, frame, entry.string.c_str(), (lldb::Format)entry.number))
1611 case Entry::Type::ScriptFrame:
1614 StackFrame *frame = exe_ctx->GetFramePtr();
1616 return RunScriptFormatKeyword (s, sc, exe_ctx, frame, entry.string.c_str());
1620 case Entry::Type::FunctionID:
1625 s.Printf("function{0x%8.8" PRIx64 "}", sc->function->GetID());
1628 else if (sc->symbol)
1630 s.Printf("symbol[%u]", sc->symbol->GetID());
1636 case Entry::Type::FunctionDidChange:
1637 return function_changed;
1639 case Entry::Type::FunctionInitialFunction:
1640 return initial_function;
1642 case Entry::Type::FunctionName:
1644 Language *language_plugin = nullptr;
1645 bool language_plugin_handled = false;
1648 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1649 else if (sc->symbol)
1650 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1651 if (language_plugin)
1653 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1655 Language::FunctionNameRepresentation::eName,
1658 if (language_plugin_handled)
1660 s.PutCString(ss.GetData());
1665 const char *name = nullptr;
1667 name = sc->function->GetName().AsCString(nullptr);
1668 else if (sc->symbol)
1669 name = sc->symbol->GetName().AsCString(nullptr);
1676 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1679 const InlineFunctionInfo *inline_info = sc->block->GetInlinedFunctionInfo();
1682 s.PutCString(" [inlined] ");
1683 inline_info->GetName(sc->function->GetLanguage()).Dump(&s);
1693 case Entry::Type::FunctionNameNoArgs:
1695 Language *language_plugin = nullptr;
1696 bool language_plugin_handled = false;
1699 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1700 else if (sc->symbol)
1701 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1702 if (language_plugin)
1704 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1706 Language::FunctionNameRepresentation::eNameWithNoArgs,
1709 if (language_plugin_handled)
1711 s.PutCString(ss.GetData());
1718 name = sc->function->GetNameNoArguments();
1719 else if (sc->symbol)
1720 name = sc->symbol->GetNameNoArguments();
1723 s.PutCString(name.GetCString());
1730 case Entry::Type::FunctionNameWithArgs:
1732 Language *language_plugin = nullptr;
1733 bool language_plugin_handled = false;
1736 language_plugin = Language::FindPlugin(sc->function->GetLanguage());
1737 else if (sc->symbol)
1738 language_plugin = Language::FindPlugin(sc->symbol->GetLanguage());
1739 if (language_plugin)
1741 language_plugin_handled = language_plugin->GetFunctionDisplayName(sc,
1743 Language::FunctionNameRepresentation::eNameWithArgs,
1746 if (language_plugin_handled)
1748 s.PutCString(ss.GetData());
1753 // Print the function name with arguments in it
1756 ExecutionContextScope *exe_scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
1757 const char *cstr = sc->function->GetName().AsCString(nullptr);
1760 const InlineFunctionInfo *inline_info = nullptr;
1761 VariableListSP variable_list_sp;
1762 bool get_function_vars = true;
1765 Block *inline_block = sc->block->GetContainingInlinedBlock ();
1769 get_function_vars = false;
1770 inline_info = sc->block->GetInlinedFunctionInfo();
1772 variable_list_sp = inline_block->GetBlockVariableList (true);
1776 if (get_function_vars)
1778 variable_list_sp = sc->function->GetBlock(true).GetBlockVariableList (true);
1783 s.PutCString (cstr);
1784 s.PutCString (" [inlined] ");
1785 cstr = inline_info->GetName(sc->function->GetLanguage()).GetCString();
1789 if (variable_list_sp)
1790 variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument, args);
1791 if (args.GetSize() > 0)
1793 const char *open_paren = strchr (cstr, '(');
1794 const char *close_paren = nullptr;
1795 const char *generic = strchr(cstr, '<');
1796 // if before the arguments list begins there is a template sign
1797 // then scan to the end of the generic args before you try to find
1798 // the arguments list
1799 if (generic && open_paren && generic < open_paren)
1801 int generic_depth = 1;
1804 *generic && generic_depth > 0;
1807 if (*generic == '<')
1809 if (*generic == '>')
1813 open_paren = strchr(generic, '(');
1815 open_paren = nullptr;
1819 if (IsToken (open_paren, "(anonymous namespace)"))
1821 open_paren = strchr (open_paren + strlen("(anonymous namespace)"), '(');
1823 close_paren = strchr (open_paren, ')');
1826 close_paren = strchr (open_paren, ')');
1830 s.Write(cstr, open_paren - cstr + 1);
1833 s.PutCString (cstr);
1836 const size_t num_args = args.GetSize();
1837 for (size_t arg_idx = 0; arg_idx < num_args; ++arg_idx)
1841 VariableSP var_sp (args.GetVariableAtIndex (arg_idx));
1842 ValueObjectSP var_value_sp (ValueObjectVariable::Create (exe_scope, var_sp));
1844 const char *var_representation = nullptr;
1845 const char *var_name = var_value_sp->GetName().GetCString();
1846 if (var_value_sp->GetCompilerType().IsValid())
1848 if (var_value_sp && exe_scope->CalculateTarget())
1849 var_value_sp = var_value_sp->GetQualifiedRepresentationIfAvailable(exe_scope->CalculateTarget()->TargetProperties::GetPreferDynamicValue(),
1850 exe_scope->CalculateTarget()->TargetProperties::GetEnableSyntheticValue());
1851 if (var_value_sp->GetCompilerType().IsAggregateType() &&
1852 DataVisualization::ShouldPrintAsOneLiner(*var_value_sp))
1854 static StringSummaryFormat format(TypeSummaryImpl::Flags()
1855 .SetHideItemNames(false)
1856 .SetShowMembersOneLiner(true),
1858 format.FormatObject(var_value_sp.get(), buffer, TypeSummaryOptions());
1859 var_representation = buffer.c_str();
1862 var_value_sp->DumpPrintableRepresentation(ss,
1863 ValueObject::ValueObjectRepresentationStyle::eValueObjectRepresentationStyleSummary,
1865 ValueObject::PrintableRepresentationSpecialCases::ePrintableRepresentationSpecialCasesAllow,
1869 if (ss.GetData() && ss.GetSize())
1870 var_representation = ss.GetData();
1872 s.PutCString (", ");
1873 if (var_value_sp->GetError().Success())
1875 if (var_representation)
1876 s.Printf ("%s=%s", var_name, var_representation);
1878 s.Printf ("%s=%s at %s", var_name, var_value_sp->GetTypeName().GetCString(), var_value_sp->GetLocationAsCString());
1881 s.Printf ("%s=<unavailable>", var_name);
1885 s.PutCString (close_paren);
1897 else if (sc->symbol)
1899 const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1910 case Entry::Type::FunctionAddrOffset:
1913 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, *addr, false, false, false))
1918 case Entry::Type::FunctionAddrOffsetConcrete:
1921 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, *addr, true, true, true))
1926 case Entry::Type::FunctionLineOffset:
1927 return (DumpAddressOffsetFromFunction (s, sc, exe_ctx, sc->line_entry.range.GetBaseAddress(), false, false, false));
1929 case Entry::Type::FunctionPCOffset:
1932 StackFrame *frame = exe_ctx->GetFramePtr();
1935 if (DumpAddressOffsetFromFunction (s, sc, exe_ctx, frame->GetFrameCodeAddress(), false, false, false))
1941 case Entry::Type::FunctionChanged:
1942 return function_changed;
1944 case Entry::Type::FunctionIsOptimized:
1946 bool is_optimized = false;
1947 if (sc->function && sc->function->GetIsOptimized())
1949 is_optimized = true;
1951 return is_optimized;
1954 case Entry::Type::FunctionInitial:
1955 return initial_function;
1957 case Entry::Type::LineEntryFile:
1958 if (sc && sc->line_entry.IsValid())
1960 Module *module = sc->module_sp.get();
1963 if (DumpFile(s, sc->line_entry.file, (FileKind)entry.number))
1969 case Entry::Type::LineEntryLineNumber:
1970 if (sc && sc->line_entry.IsValid())
1972 const char *format = "%" PRIu32;
1973 if (!entry.printf_format.empty())
1974 format = entry.printf_format.c_str();
1975 s.Printf(format, sc->line_entry.line);
1980 case Entry::Type::LineEntryStartAddress:
1981 case Entry::Type::LineEntryEndAddress:
1982 if (sc && sc->line_entry.range.GetBaseAddress().IsValid())
1984 Address addr = sc->line_entry.range.GetBaseAddress();
1986 if (entry.type == Entry::Type::LineEntryEndAddress)
1987 addr.Slide(sc->line_entry.range.GetByteSize());
1988 if (DumpAddress(s, sc, exe_ctx, addr, false))
1993 case Entry::Type::CurrentPCArrow:
1994 if (addr && exe_ctx && exe_ctx->GetFramePtr())
1996 RegisterContextSP reg_ctx = exe_ctx->GetFramePtr()->GetRegisterContextSP();
1999 addr_t pc_loadaddr = reg_ctx->GetPC();
2000 if (pc_loadaddr != LLDB_INVALID_ADDRESS)
2003 pc.SetLoadAddress (pc_loadaddr, exe_ctx->GetTargetPtr());
2020 DumpCommaSeparatedChildEntryNames (Stream &s, const FormatEntity::Entry::Definition *parent)
2022 if (parent->children)
2024 const size_t n = parent->num_children;
2025 for (size_t i = 0; i < n; ++i)
2029 s.Printf ("\"%s\"", parent->children[i].name);
2037 ParseEntry (const llvm::StringRef &format_str,
2038 const FormatEntity::Entry::Definition *parent,
2039 FormatEntity::Entry &entry)
2043 const size_t sep_pos = format_str.find_first_of(".[:");
2044 const char sep_char = (sep_pos == llvm::StringRef::npos) ? '\0' : format_str[sep_pos];
2045 llvm::StringRef key = format_str.substr(0, sep_pos);
2047 const size_t n = parent->num_children;
2048 for (size_t i = 0; i < n; ++i)
2050 const FormatEntity::Entry::Definition *entry_def = parent->children + i;
2051 if (key.equals(entry_def->name) || entry_def->name[0] == '*')
2053 llvm::StringRef value;
2055 value = format_str.substr(sep_pos + (entry_def->keep_separator ? 0 : 1));
2056 switch (entry_def->type)
2058 case FormatEntity::Entry::Type::ParentString:
2059 entry.string = format_str.str();
2060 return error; // Success
2062 case FormatEntity::Entry::Type::ParentNumber:
2063 entry.number = entry_def->data;
2064 return error; // Success
2066 case FormatEntity::Entry::Type::InsertString:
2067 entry.type = entry_def->type;
2068 entry.string = entry_def->string;
2069 return error; // Success
2072 entry.type = entry_def->type;
2078 if (entry_def->type == FormatEntity::Entry::Type::Invalid)
2080 if (entry_def->children)
2082 StreamString error_strm;
2083 error_strm.Printf("'%s' can't be specified on its own, you must access one of its children: ", entry_def->name);
2084 DumpCommaSeparatedChildEntryNames (error_strm, entry_def);
2085 error.SetErrorStringWithFormat("%s", error_strm.GetString().c_str());
2087 else if (sep_char == ':')
2089 // Any value whose separator is a with a ':' means this value has a string argument
2090 // that needs to be stored in the entry (like "${script.var:}").
2091 // In this case the string value is the empty string which is ok.
2095 error.SetErrorStringWithFormat("%s", "invalid entry definitions");
2101 if (entry_def->children)
2103 error = ParseEntry (value, entry_def, entry);
2105 else if (sep_char == ':')
2107 // Any value whose separator is a with a ':' means this value has a string argument
2108 // that needs to be stored in the entry (like "${script.var:modulename.function}")
2109 entry.string = value.str();
2113 error.SetErrorStringWithFormat("'%s' followed by '%s' but it has no children",
2115 value.str().c_str());
2121 StreamString error_strm;
2122 if (parent->type == FormatEntity::Entry::Type::Root)
2123 error_strm.Printf("invalid top level item '%s'. Valid top level items are: ", key.str().c_str());
2125 error_strm.Printf("invalid member '%s' in '%s'. Valid members are: ", key.str().c_str(), parent->name);
2126 DumpCommaSeparatedChildEntryNames (error_strm, parent);
2127 error.SetErrorStringWithFormat("%s", error_strm.GetString().c_str());
2131 static const FormatEntity::Entry::Definition *
2132 FindEntry (const llvm::StringRef &format_str, const FormatEntity::Entry::Definition *parent, llvm::StringRef &remainder)
2136 std::pair<llvm::StringRef, llvm::StringRef> p = format_str.split('.');
2137 const size_t n = parent->num_children;
2138 for (size_t i = 0; i < n; ++i)
2140 const FormatEntity::Entry::Definition *entry_def = parent->children + i;
2141 if (p.first.equals(entry_def->name) || entry_def->name[0] == '*')
2143 if (p.second.empty())
2145 if (format_str.back() == '.')
2146 remainder = format_str.drop_front(format_str.size() - 1);
2148 remainder = llvm::StringRef(); // Exact match
2153 if (entry_def->children)
2155 return FindEntry (p.second, entry_def, remainder);
2159 remainder = p.second;
2165 remainder = format_str;
2170 FormatEntity::ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint32_t depth)
2173 while (!format.empty() && error.Success())
2175 const size_t non_special_chars = format.find_first_of("${}\\");
2177 if (non_special_chars == llvm::StringRef::npos)
2179 // No special characters, just string bytes so add them and we are done
2180 parent_entry.AppendText(format);
2184 if (non_special_chars > 0)
2186 // We have a special character, so add all characters before these as a plain string
2187 parent_entry.AppendText(format.substr(0,non_special_chars));
2188 format = format.drop_front(non_special_chars);
2198 format = format.drop_front(); // Skip the '{'
2199 Entry scope_entry(Entry::Type::Scope);
2200 error = FormatEntity::ParseInternal (format, scope_entry, depth+1);
2203 parent_entry.AppendEntry(std::move(scope_entry));
2209 error.SetErrorString("unmatched '}' character");
2211 format = format.drop_front(); // Skip the '}' as we are at the end of the scope
2216 format = format.drop_front(); // Skip the '\' character
2219 error.SetErrorString("'\\' character was not followed by another character");
2223 const char desens_char = format[0];
2224 format = format.drop_front(); // Skip the desensitized char character
2225 switch (desens_char)
2227 case 'a': parent_entry.AppendChar('\a'); break;
2228 case 'b': parent_entry.AppendChar('\b'); break;
2229 case 'f': parent_entry.AppendChar('\f'); break;
2230 case 'n': parent_entry.AppendChar('\n'); break;
2231 case 'r': parent_entry.AppendChar('\r'); break;
2232 case 't': parent_entry.AppendChar('\t'); break;
2233 case 'v': parent_entry.AppendChar('\v'); break;
2234 case '\'': parent_entry.AppendChar('\''); break;
2235 case '\\': parent_entry.AppendChar('\\'); break;
2237 // 1 to 3 octal chars
2239 // Make a string that can hold onto the initial zero char,
2240 // up to 3 octal digits, and a terminating NULL.
2241 char oct_str[5] = { 0, 0, 0, 0, 0 };
2244 for (i = 0; (format[i] >= '0' && format[i] <= '7') && i < 4; ++i)
2245 oct_str[i] = format[i];
2247 // We don't want to consume the last octal character since
2248 // the main for loop will do this for us, so we advance p by
2249 // one less than i (even if i is zero)
2250 format = format.drop_front(i);
2251 unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
2252 if (octal_value <= UINT8_MAX)
2254 parent_entry.AppendChar((char)octal_value);
2258 error.SetErrorString("octal number is larger than a single byte");
2265 // hex number in the format
2266 if (isxdigit(format[0]))
2268 // Make a string that can hold onto two hex chars plus a
2270 char hex_str[3] = { 0,0,0 };
2271 hex_str[0] = format[0];
2273 format = format.drop_front();
2275 if (isxdigit(format[0]))
2277 hex_str[1] = format[0];
2278 format = format.drop_front();
2281 unsigned long hex_value = strtoul(hex_str, nullptr, 16);
2282 if (hex_value <= UINT8_MAX)
2284 parent_entry.AppendChar((char)hex_value);
2288 error.SetErrorString("hex number is larger than a single byte");
2294 parent_entry.AppendChar(desens_char);
2299 // Just desensitize any other character by just printing what
2300 // came after the '\'
2301 parent_entry.AppendChar(desens_char);
2308 if (format.size() == 1)
2310 // '$' at the end of a format string, just print the '$'
2311 parent_entry.AppendText("$");
2315 format = format.drop_front(); // Skip the '$'
2317 if (format[0] == '{')
2319 format = format.drop_front(); // Skip the '{'
2321 llvm::StringRef variable, variable_format;
2322 error = FormatEntity::ExtractVariableInfo (format, variable, variable_format);
2325 bool verify_is_thread_id = false;
2327 if (!variable_format.empty())
2329 entry.printf_format = variable_format.str();
2331 // If the format contains a '%' we are going to assume this is
2332 // a printf style format. So if you want to format your thread ID
2333 // using "0x%llx" you can use:
2334 // ${thread.id%0x%llx}
2336 // If there is no '%' in the format, then it is assumed to be a
2337 // LLDB format name, or one of the extended formats specified in
2338 // the switch statement below.
2340 if (entry.printf_format.find('%') == std::string::npos)
2342 bool clear_printf = false;
2344 if (FormatManager::GetFormatFromCString(entry.printf_format.c_str(),
2348 // We have an LLDB format, so clear the printf format
2349 clear_printf = true;
2351 else if (entry.printf_format.size() == 1)
2353 switch (entry.printf_format[0])
2355 case '@': // if this is an @ sign, print ObjC description
2356 entry.number = ValueObject::eValueObjectRepresentationStyleLanguageSpecific;
2357 clear_printf = true;
2359 case 'V': // if this is a V, print the value using the default format
2360 entry.number = ValueObject::eValueObjectRepresentationStyleValue;
2361 clear_printf = true;
2363 case 'L': // if this is an L, print the location of the value
2364 entry.number = ValueObject::eValueObjectRepresentationStyleLocation;
2365 clear_printf = true;
2367 case 'S': // if this is an S, print the summary after all
2368 entry.number = ValueObject::eValueObjectRepresentationStyleSummary;
2369 clear_printf = true;
2371 case '#': // if this is a '#', print the number of children
2372 entry.number = ValueObject::eValueObjectRepresentationStyleChildrenCount;
2373 clear_printf = true;
2375 case 'T': // if this is a 'T', print the type
2376 entry.number = ValueObject::eValueObjectRepresentationStyleType;
2377 clear_printf = true;
2379 case 'N': // if this is a 'N', print the name
2380 entry.number = ValueObject::eValueObjectRepresentationStyleName;
2381 clear_printf = true;
2383 case '>': // if this is a '>', print the expression path
2384 entry.number = ValueObject::eValueObjectRepresentationStyleExpressionPath;
2385 clear_printf = true;
2388 error.SetErrorStringWithFormat("invalid format: '%s'", entry.printf_format.c_str());
2392 else if (FormatManager::GetFormatFromCString(entry.printf_format.c_str(),
2396 clear_printf = true;
2398 else if (entry.printf_format == "tid")
2400 verify_is_thread_id = true;
2404 error.SetErrorStringWithFormat("invalid format: '%s'", entry.printf_format.c_str());
2408 // Our format string turned out to not be a printf style format
2409 // so lets clear the string
2411 entry.printf_format.clear();
2415 // Check for dereferences
2416 if (variable[0] == '*')
2419 variable = variable.drop_front();
2422 error = ParseEntry (variable, &g_root, entry);
2426 if (verify_is_thread_id)
2428 if (entry.type != Entry::Type::ThreadID &&
2429 entry.type != Entry::Type::ThreadProtocolID)
2431 error.SetErrorString("the 'tid' format can only be used on ${thread.id} and ${thread.protocol_id}");
2437 case Entry::Type::Variable:
2438 case Entry::Type::VariableSynthetic:
2439 if (entry.number == 0)
2441 if (entry.string.empty())
2442 entry.number = ValueObject::eValueObjectRepresentationStyleValue;
2444 entry.number = ValueObject::eValueObjectRepresentationStyleSummary;
2448 // Make sure someone didn't try to dereference anything but ${var} or ${svar}
2451 error.SetErrorStringWithFormat("${%s} can't be dereferenced, only ${var} and ${svar} can.", variable.str().c_str());
2455 // Check if this entry just wants to insert a constant string
2456 // value into the parent_entry, if so, insert the string with
2457 // AppendText, else append the entry to the parent_entry.
2458 if (entry.type == Entry::Type::InsertString)
2459 parent_entry.AppendText(entry.string.c_str());
2461 parent_entry.AppendEntry(std::move(entry));
2471 FormatEntity::ExtractVariableInfo (llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
2474 variable_name = llvm::StringRef();
2475 variable_format = llvm::StringRef();
2477 const size_t paren_pos = format_str.find('}');
2478 if (paren_pos != llvm::StringRef::npos)
2480 const size_t percent_pos = format_str.find('%');
2481 if (percent_pos < paren_pos)
2483 if (percent_pos > 0)
2485 if (percent_pos > 1)
2486 variable_name = format_str.substr(0, percent_pos);
2487 variable_format = format_str.substr(percent_pos + 1, paren_pos - (percent_pos + 1));
2492 variable_name = format_str.substr(0, paren_pos);
2494 // Strip off elements and the formatting and the trailing '}'
2495 format_str = format_str.substr(paren_pos + 1);
2499 error.SetErrorStringWithFormat("missing terminating '}' character for '${%s'", format_str.str().c_str());
2505 FormatEntity::FormatFileSpec (const FileSpec &file_spec, Stream &s, llvm::StringRef variable_name, llvm::StringRef variable_format)
2507 if (variable_name.empty() || variable_name.equals(".fullpath"))
2512 else if (variable_name.equals(".basename"))
2514 s.PutCString(file_spec.GetFilename().AsCString(""));
2517 else if (variable_name.equals(".dirname"))
2519 s.PutCString(file_spec.GetFilename().AsCString(""));
2526 MakeMatch (const llvm::StringRef &prefix, const char *suffix)
2528 std::string match(prefix.str());
2529 match.append(suffix);
2534 AddMatches (const FormatEntity::Entry::Definition *def,
2535 const llvm::StringRef &prefix,
2536 const llvm::StringRef &match_prefix,
2537 StringList &matches)
2539 const size_t n = def->num_children;
2542 for (size_t i = 0; i < n; ++i)
2544 std::string match = prefix.str();
2545 if (match_prefix.empty())
2546 matches.AppendString(MakeMatch (prefix, def->children[i].name));
2547 else if (strncmp(def->children[i].name, match_prefix.data(), match_prefix.size()) == 0)
2548 matches.AppendString(MakeMatch (prefix, def->children[i].name + match_prefix.size()));
2554 FormatEntity::AutoComplete (const char *s,
2555 int match_start_point,
2556 int max_return_elements,
2557 bool &word_complete,
2558 StringList &matches)
2560 word_complete = false;
2561 llvm::StringRef str(s + match_start_point);
2564 const size_t dollar_pos = str.rfind('$');
2565 if (dollar_pos != llvm::StringRef::npos)
2567 // Hitting TAB after $ at the end of the string add a "{"
2568 if (dollar_pos == str.size() - 1)
2570 std::string match = str.str();
2572 matches.AppendString(std::move(match));
2574 else if (str[dollar_pos + 1] == '{')
2576 const size_t close_pos = str.find('}', dollar_pos + 2);
2577 if (close_pos == llvm::StringRef::npos)
2579 const size_t format_pos = str.find('%', dollar_pos + 2);
2580 if (format_pos == llvm::StringRef::npos)
2582 llvm::StringRef partial_variable (str.substr(dollar_pos + 2));
2583 if (partial_variable.empty())
2585 // Suggest all top level entites as we are just past "${"
2586 AddMatches(&g_root, str, llvm::StringRef(), matches);
2590 // We have a partially specified variable, find it
2591 llvm::StringRef remainder;
2592 const FormatEntity::Entry::Definition* entry_def = FindEntry (partial_variable, &g_root, remainder);
2595 const size_t n = entry_def->num_children;
2597 if (remainder.empty())
2602 // "${thread.info" <TAB>
2603 matches.AppendString(MakeMatch(str, "."));
2607 // "${thread.id" <TAB>
2608 matches.AppendString(MakeMatch (str, "}"));
2609 word_complete = true;
2612 else if (remainder.equals("."))
2614 // "${thread." <TAB>
2615 AddMatches(entry_def, str, llvm::StringRef(), matches);
2619 // We have a partial match
2621 AddMatches(entry_def, str, remainder, matches);
2629 return matches.GetSize();