1 //===-- Xcode.cpp -----------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "Xcode.h" 11 #include <string> 12 13 using namespace std; 14 using namespace lldb_perf; 15 16 void 17 Xcode::FetchVariable (SBValue value, uint32_t expand, bool verbose) 18 { 19 auto name = value.GetName(); 20 auto num_value = value.GetValueAsUnsigned(0); 21 auto summary = value.GetSummary(); 22 auto in_scope = value.IsInScope(); 23 auto has_children = value.MightHaveChildren(); 24 auto type_1 = value.GetType(); 25 auto type_2 = value.GetType(); 26 auto type_name_1 = value.GetTypeName(); 27 auto type_3 = value.GetType(); 28 auto type_name_2 = value.GetTypeName(); 29 if (verbose) 30 printf("%s %s = 0x%llx (%llu) %s\n",value.GetTypeName(),value.GetName(),num_value, num_value,summary); 31 if (expand > 0) 32 { 33 auto count = value.GetNumChildren(); 34 for (int i = 0; i < count; i++) 35 { 36 SBValue child(value.GetChildAtIndex(i, lldb::eDynamicCanRunTarget, true)); 37 FetchVariable (child,expand-1,verbose); 38 } 39 } 40 } 41 42 void 43 Xcode::FetchModules (SBTarget target, bool verbose) 44 { 45 auto count = target.GetNumModules(); 46 for (int i = 0; i < count; i++) 47 { 48 SBModule module(target.GetModuleAtIndex(i)); 49 auto fspec = module.GetFileSpec(); 50 std::string path(1024,0); 51 fspec.GetPath(&path[0],1024); 52 auto uuid = module.GetUUIDBytes(); 53 if (verbose) 54 { 55 printf("%s %s\n",path.c_str(),module.GetUUIDString()); 56 } 57 } 58 } 59 60 void 61 Xcode::FetchVariables (SBFrame frame, uint32_t expand, bool verbose) 62 { 63 auto values = frame.GetVariables (true,true,true,false, eDynamicCanRunTarget); 64 auto count = values.GetSize(); 65 for (int i = 0; i < count; i++) 66 { 67 SBValue value(values.GetValueAtIndex(i)); 68 FetchVariable (value,expand,verbose); 69 } 70 } 71 72 void 73 Xcode::FetchFrames(SBProcess process, bool variables, bool verbose) 74 { 75 auto pCount = process.GetNumThreads(); 76 for (int p = 0; p < pCount; p++) 77 { 78 SBThread thread(process.GetThreadAtIndex(p)); 79 auto tCount = thread.GetNumFrames (); 80 if (verbose) 81 printf("%s %d %d {%d}\n",thread.GetQueueName(),tCount,thread.GetStopReason(),eStopReasonBreakpoint); 82 for (int t = 0; t < tCount; t++) 83 { 84 SBFrame frame(thread.GetFrameAtIndex(t)); 85 auto fp = frame.GetFP(); 86 SBThread thread_dup = frame.GetThread(); 87 SBFileSpec filespec(process.GetTarget().GetExecutable()); 88 std::string path(1024,0); 89 filespec.GetPath(&path[0],1024); 90 auto state = process.GetState(); 91 auto pCount_dup = process.GetNumThreads(); 92 auto byte_size = process.GetAddressByteSize(); 93 auto pc = frame.GetPC(); 94 SBSymbolContext context(frame.GetSymbolContext(0x0000006e)); 95 SBModule module(context.GetModule()); 96 SBLineEntry entry(context.GetLineEntry()); 97 SBFileSpec entry_filespec(process.GetTarget().GetExecutable()); 98 std::string entry_path(1024,0); 99 entry_filespec.GetPath(&entry_path[0],1024); 100 auto line_1 = entry.GetLine(); 101 auto line_2 = entry.GetLine(); 102 auto fname = frame.GetFunctionName(); 103 if (verbose) 104 printf("%llu %s %d %d %llu %s %d %s\n",fp,path.c_str(),state,byte_size,pc,entry_path.c_str(),line_1,fname); 105 if (variables) 106 FetchVariables (frame, 0, verbose); 107 } 108 } 109 } 110 111 void 112 Xcode::RunExpression (SBFrame frame, const char* expression, bool po, bool verbose) 113 { 114 SBValue value (frame.EvaluateExpression (expression, eDynamicCanRunTarget)); 115 FetchVariable (value,0,verbose); 116 if (po) 117 { 118 auto descr = value.GetObjectDescription(); 119 if (descr) 120 printf("po = %s\n",descr); 121 } 122 } 123 124 void 125 Xcode::Next (SBThread thread) 126 { 127 thread.StepOver(); 128 } 129 130 void 131 Xcode::Continue (SBProcess process) 132 { 133 process.Continue(); 134 } 135 136 void 137 Xcode::RunCommand (SBDebugger debugger, const char* cmd, bool verbose) 138 { 139 SBCommandReturnObject sb_ret; 140 auto interpreter = debugger.GetCommandInterpreter(); 141 interpreter.HandleCommand(cmd,sb_ret); 142 if (verbose) 143 printf("%s\n%s\n",sb_ret.GetOutput(false),sb_ret.GetError(false)); 144 } 145 146 SBThread 147 Xcode::GetThreadWithStopReason (SBProcess process, StopReason reason) 148 { 149 auto threads_count = process.GetNumThreads(); 150 for (auto thread_num = 0; thread_num < threads_count; thread_num++) 151 { 152 SBThread thread(process.GetThreadAtIndex(thread_num)); 153 if (thread.GetStopReason() == reason) 154 { 155 return thread; 156 } 157 } 158 return SBThread(); 159 } 160 161 SBBreakpoint 162 Xcode::CreateFileLineBreakpoint (SBTarget target, const char* file, uint32_t line) 163 { 164 return target.BreakpointCreateByLocation(file, line); 165 } 166