Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBTarget.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 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBTarget.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-public.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBDebugger.h" |
| 15 | #include "lldb/API/SBBreakpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 17 | #include "lldb/API/SBListener.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBModule.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBSourceManager.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBProcess.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBStream.h" |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Breakpoint/BreakpointID.h" |
| 24 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 25 | #include "lldb/Breakpoint/BreakpointList.h" |
| 26 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 27 | #include "lldb/Core/Address.h" |
| 28 | #include "lldb/Core/AddressResolver.h" |
| 29 | #include "lldb/Core/AddressResolverName.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/ArchSpec.h" |
| 31 | #include "lldb/Core/Debugger.h" |
| 32 | #include "lldb/Core/Disassembler.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 33 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/RegularExpression.h" |
| 35 | #include "lldb/Core/SearchFilter.h" |
| 36 | #include "lldb/Core/STLUtils.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 37 | #include "lldb/Core/ValueObjectList.h" |
| 38 | #include "lldb/Core/ValueObjectVariable.h" |
| 39 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 40 | #include "lldb/Host/Host.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 41 | #include "lldb/Interpreter/Args.h" |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | #include "lldb/Target/Process.h" |
| 45 | #include "lldb/Target/Target.h" |
| 46 | #include "lldb/Target/TargetList.h" |
| 47 | |
| 48 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 49 | #include "../source/Commands/CommandObjectBreakpoint.h" |
| 50 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
| 52 | using namespace lldb; |
| 53 | using namespace lldb_private; |
| 54 | |
| 55 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 56 | |
| 57 | //---------------------------------------------------------------------- |
| 58 | // SBTarget constructor |
| 59 | //---------------------------------------------------------------------- |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 60 | SBTarget::SBTarget () : |
| 61 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | { |
| 63 | } |
| 64 | |
| 65 | SBTarget::SBTarget (const SBTarget& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 66 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | { |
| 68 | } |
| 69 | |
| 70 | SBTarget::SBTarget(const TargetSP& target_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 71 | m_opaque_sp (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | { |
| 73 | } |
| 74 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 75 | const SBTarget& |
| 76 | SBTarget::operator = (const SBTarget& rhs) |
| 77 | { |
| 78 | if (this != &rhs) |
| 79 | m_opaque_sp = rhs.m_opaque_sp; |
| 80 | return *this; |
| 81 | } |
| 82 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | //---------------------------------------------------------------------- |
| 84 | // Destructor |
| 85 | //---------------------------------------------------------------------- |
| 86 | SBTarget::~SBTarget() |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | bool |
| 91 | SBTarget::IsValid () const |
| 92 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 93 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | SBProcess |
| 97 | SBTarget::GetProcess () |
| 98 | { |
| 99 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 100 | ProcessSP process_sp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 101 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 102 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 103 | process_sp = m_opaque_sp->GetProcessSP(); |
| 104 | sb_process.SetSP (process_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 105 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 106 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 107 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 108 | if (log) |
| 109 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 110 | log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 111 | m_opaque_sp.get(), process_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | return sb_process; |
| 115 | } |
| 116 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 117 | SBDebugger |
| 118 | SBTarget::GetDebugger () const |
| 119 | { |
| 120 | SBDebugger debugger; |
| 121 | if (m_opaque_sp) |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 122 | debugger.reset (m_opaque_sp->GetDebugger().shared_from_this()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 123 | return debugger; |
| 124 | } |
| 125 | |
Jim Ingham | b5871fe | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 126 | SBProcess |
| 127 | SBTarget::LaunchSimple |
| 128 | ( |
| 129 | char const **argv, |
| 130 | char const **envp, |
| 131 | const char *working_directory |
| 132 | ) |
| 133 | { |
| 134 | char *stdin_path = NULL; |
| 135 | char *stdout_path = NULL; |
| 136 | char *stderr_path = NULL; |
| 137 | uint32_t launch_flags = 0; |
| 138 | bool stop_at_entry = false; |
| 139 | SBError error; |
| 140 | SBListener listener = GetDebugger().GetListener(); |
| 141 | return Launch (listener, |
| 142 | argv, |
| 143 | envp, |
| 144 | stdin_path, |
| 145 | stdout_path, |
| 146 | stderr_path, |
| 147 | working_directory, |
| 148 | launch_flags, |
| 149 | stop_at_entry, |
| 150 | error); |
| 151 | } |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 152 | |
| 153 | SBProcess |
| 154 | SBTarget::Launch |
| 155 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 156 | SBListener &listener, |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 157 | char const **argv, |
| 158 | char const **envp, |
| 159 | const char *stdin_path, |
| 160 | const char *stdout_path, |
| 161 | const char *stderr_path, |
| 162 | const char *working_directory, |
| 163 | uint32_t launch_flags, // See LaunchFlags |
| 164 | bool stop_at_entry, |
| 165 | lldb::SBError& error |
| 166 | ) |
| 167 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 168 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 169 | |
| 170 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 171 | { |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 172 | log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", |
| 173 | m_opaque_sp.get(), |
| 174 | argv, |
| 175 | envp, |
| 176 | stdin_path ? stdin_path : "NULL", |
| 177 | stdout_path ? stdout_path : "NULL", |
| 178 | stderr_path ? stderr_path : "NULL", |
| 179 | working_directory ? working_directory : "NULL", |
| 180 | launch_flags, |
| 181 | stop_at_entry, |
| 182 | error.get()); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 183 | } |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 184 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 185 | ProcessSP process_sp; |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 186 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 187 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 188 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 189 | |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 190 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) |
| 191 | launch_flags |= eLaunchFlagDisableASLR; |
| 192 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 193 | StateType state = eStateInvalid; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 194 | process_sp = m_opaque_sp->GetProcessSP(); |
| 195 | if (process_sp) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 196 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 197 | state = process_sp->GetState(); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 198 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 199 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 200 | { |
| 201 | if (state == eStateAttaching) |
| 202 | error.SetErrorString ("process attach is in progress"); |
| 203 | else |
| 204 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 205 | return sb_process; |
| 206 | } |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 209 | if (state == eStateConnected) |
| 210 | { |
| 211 | // If we are already connected, then we have already specified the |
| 212 | // listener, so if a valid listener is supplied, we need to error out |
| 213 | // to let the client know. |
| 214 | if (listener.IsValid()) |
| 215 | { |
| 216 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 217 | return sb_process; |
| 218 | } |
| 219 | } |
| 220 | else |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 221 | { |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 222 | if (listener.IsValid()) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 223 | process_sp = m_opaque_sp->CreateProcess (listener.ref()); |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 224 | else |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 225 | process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 226 | } |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 227 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 228 | if (process_sp) |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 229 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 230 | sb_process.SetSP (process_sp); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 231 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) |
| 232 | launch_flags |= eLaunchFlagDisableSTDIO; |
| 233 | |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 234 | ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); |
| 235 | |
| 236 | Module *exe_module = m_opaque_sp->GetExecutableModulePointer(); |
| 237 | if (exe_module) |
Greg Clayton | 1d1f39e | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 238 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 239 | if (argv) |
| 240 | launch_info.GetArguments().AppendArguments (argv); |
| 241 | if (envp) |
| 242 | launch_info.GetEnvironmentEntries ().SetArguments (envp); |
| 243 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 244 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 245 | if (error.Success()) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 246 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 247 | // We we are stopping at the entry point, we can return now! |
| 248 | if (stop_at_entry) |
| 249 | return sb_process; |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 250 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 251 | // Make sure we are stopped at the entry |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 252 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 253 | if (state == eStateStopped) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 254 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 255 | // resume the process to skip the entry point |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 256 | error.SetError (process_sp->Resume()); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 257 | if (error.Success()) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 258 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 259 | // If we are doing synchronous mode, then wait for the |
| 260 | // process to stop yet again! |
| 261 | if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 262 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | } |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 266 | } |
| 267 | else |
| 268 | { |
| 269 | error.SetErrorString ("unable to create lldb_private::Process"); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | error.SetErrorString ("SBTarget is invalid"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 276 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 277 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 278 | if (log) |
| 279 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 280 | log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 281 | m_opaque_sp.get(), process_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 284 | return sb_process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Greg Clayton | d5b0b44 | 2011-12-02 02:10:57 +0000 | [diff] [blame] | 287 | #if defined(__APPLE__) |
| 288 | |
| 289 | lldb::SBProcess |
| 290 | SBTarget::AttachToProcessWithID (SBListener &listener, |
| 291 | ::pid_t pid, |
| 292 | lldb::SBError& error) |
| 293 | { |
| 294 | return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); |
| 295 | } |
| 296 | |
| 297 | #endif // #if defined(__APPLE__) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 298 | |
| 299 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 300 | SBTarget::AttachToProcessWithID |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 301 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 302 | SBListener &listener, |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 303 | lldb::pid_t pid,// The process ID to attach to |
| 304 | SBError& error // An error explaining what went wrong if attach fails |
| 305 | ) |
| 306 | { |
| 307 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 308 | ProcessSP process_sp; |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 309 | if (m_opaque_sp) |
| 310 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 311 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 312 | |
| 313 | StateType state = eStateInvalid; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 314 | process_sp = m_opaque_sp->GetProcessSP(); |
| 315 | if (process_sp) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 316 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 317 | state = process_sp->GetState(); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 318 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 319 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 320 | { |
| 321 | if (state == eStateAttaching) |
| 322 | error.SetErrorString ("process attach is in progress"); |
| 323 | else |
| 324 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 325 | return sb_process; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if (state == eStateConnected) |
| 330 | { |
| 331 | // If we are already connected, then we have already specified the |
| 332 | // listener, so if a valid listener is supplied, we need to error out |
| 333 | // to let the client know. |
| 334 | if (listener.IsValid()) |
| 335 | { |
| 336 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 337 | return sb_process; |
| 338 | } |
| 339 | } |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 340 | else |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 341 | { |
| 342 | if (listener.IsValid()) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 343 | process_sp = m_opaque_sp->CreateProcess (listener.ref()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 344 | else |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 345 | process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 346 | } |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 347 | if (process_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 348 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 349 | sb_process.SetSP (process_sp); |
| 350 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 351 | ProcessAttachInfo attach_info; |
| 352 | attach_info.SetProcessID (pid); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 353 | error.SetError (process_sp->Attach (attach_info)); |
Johnny Chen | 535960e | 2011-06-17 00:51:15 +0000 | [diff] [blame] | 354 | // If we are doing synchronous mode, then wait for the |
| 355 | // process to stop! |
| 356 | if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 357 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 358 | } |
| 359 | else |
| 360 | { |
| 361 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 362 | } |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | error.SetErrorString ("SBTarget is invalid"); |
| 367 | } |
| 368 | return sb_process; |
| 369 | |
| 370 | } |
| 371 | |
| 372 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 373 | SBTarget::AttachToProcessWithName |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 374 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 375 | SBListener &listener, |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 376 | const char *name, // basename of process to attach to |
| 377 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 378 | SBError& error // An error explaining what went wrong if attach fails |
| 379 | ) |
| 380 | { |
| 381 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 382 | ProcessSP process_sp; |
Johnny Chen | 5a4bbce | 2011-12-20 01:22:03 +0000 | [diff] [blame] | 383 | if (name && m_opaque_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 384 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 385 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 386 | |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 387 | StateType state = eStateInvalid; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 388 | process_sp = m_opaque_sp->GetProcessSP(); |
| 389 | if (process_sp) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 390 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 391 | state = process_sp->GetState(); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 392 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 393 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 394 | { |
| 395 | if (state == eStateAttaching) |
| 396 | error.SetErrorString ("process attach is in progress"); |
| 397 | else |
| 398 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 399 | return sb_process; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if (state == eStateConnected) |
| 404 | { |
| 405 | // If we are already connected, then we have already specified the |
| 406 | // listener, so if a valid listener is supplied, we need to error out |
| 407 | // to let the client know. |
| 408 | if (listener.IsValid()) |
| 409 | { |
| 410 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 411 | return sb_process; |
| 412 | } |
| 413 | } |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 414 | else |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 415 | { |
| 416 | if (listener.IsValid()) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 417 | process_sp = m_opaque_sp->CreateProcess (listener.ref()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 418 | else |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 419 | process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 420 | } |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 421 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 422 | if (process_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 423 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 424 | sb_process.SetSP (process_sp); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 425 | ProcessAttachInfo attach_info; |
| 426 | attach_info.GetExecutableFile().SetFile(name, false); |
| 427 | attach_info.SetWaitForLaunch(wait_for); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 428 | error.SetError (process_sp->Attach (attach_info)); |
Johnny Chen | 58d02ff | 2011-06-17 19:21:30 +0000 | [diff] [blame] | 429 | // If we are doing synchronous mode, then wait for the |
| 430 | // process to stop! |
| 431 | if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 432 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 433 | } |
| 434 | else |
| 435 | { |
| 436 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 437 | } |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | error.SetErrorString ("SBTarget is invalid"); |
| 442 | } |
| 443 | return sb_process; |
| 444 | |
| 445 | } |
| 446 | |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 447 | lldb::SBProcess |
| 448 | SBTarget::ConnectRemote |
| 449 | ( |
| 450 | SBListener &listener, |
| 451 | const char *url, |
| 452 | const char *plugin_name, |
| 453 | SBError& error |
| 454 | ) |
| 455 | { |
| 456 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 457 | ProcessSP process_sp; |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 458 | if (m_opaque_sp) |
| 459 | { |
| 460 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 461 | if (listener.IsValid()) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 462 | process_sp = m_opaque_sp->CreateProcess (listener.ref(), plugin_name); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 463 | else |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 464 | process_sp = m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener(), plugin_name); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 465 | |
| 466 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 467 | if (process_sp) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 468 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 469 | sb_process.SetSP (process_sp); |
| 470 | error.SetError (process_sp->ConnectRemote (url)); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 471 | } |
| 472 | else |
| 473 | { |
| 474 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 475 | } |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | error.SetErrorString ("SBTarget is invalid"); |
| 480 | } |
| 481 | return sb_process; |
| 482 | } |
| 483 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | SBFileSpec |
| 485 | SBTarget::GetExecutable () |
| 486 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 487 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | SBFileSpec exe_file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 489 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 491 | Module *exe_module = m_opaque_sp->GetExecutableModulePointer(); |
| 492 | if (exe_module) |
| 493 | exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 495 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 496 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 497 | if (log) |
| 498 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 499 | log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
| 500 | m_opaque_sp.get(), exe_file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | return exe_file_spec; |
| 504 | } |
| 505 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | SBTarget::operator == (const SBTarget &rhs) const |
| 508 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 509 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | bool |
| 513 | SBTarget::operator != (const SBTarget &rhs) const |
| 514 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 515 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 518 | lldb::TargetSP |
| 519 | SBTarget::GetSP () const |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 520 | { |
| 521 | return m_opaque_sp; |
| 522 | } |
| 523 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 524 | void |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame^] | 525 | SBTarget::SetSP (const lldb::TargetSP& target_sp) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 526 | { |
| 527 | m_opaque_sp = target_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 530 | lldb::SBAddress |
| 531 | SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 532 | { |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 533 | lldb::SBAddress sb_addr; |
| 534 | Address &addr = sb_addr.ref(); |
| 535 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 536 | { |
| 537 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 538 | if (m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) |
| 539 | return sb_addr; |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 540 | } |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 541 | |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 542 | // We have a load address that isn't in a section, just return an address |
| 543 | // with the offset filled in (the address) and the section set to NULL |
| 544 | addr.SetSection(NULL); |
| 545 | addr.SetOffset(vm_addr); |
| 546 | return sb_addr; |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Greg Clayton | afb8186 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 549 | SBSymbolContext |
| 550 | SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 551 | { |
| 552 | SBSymbolContext sc; |
Johnny Chen | e657fbc | 2011-06-29 00:05:40 +0000 | [diff] [blame] | 553 | if (m_opaque_sp && addr.IsValid()) |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 554 | m_opaque_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); |
Greg Clayton | afb8186 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 555 | return sc; |
| 556 | } |
| 557 | |
| 558 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 559 | SBBreakpoint |
| 560 | SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line) |
| 561 | { |
Greg Clayton | d6d806c | 2010-11-08 00:28:40 +0000 | [diff] [blame] | 562 | return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | SBBreakpoint |
| 566 | SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line) |
| 567 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 568 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 569 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 571 | if (m_opaque_sp.get() && line != 0) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 572 | { |
| 573 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 574 | *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 575 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 576 | |
| 577 | if (log) |
| 578 | { |
| 579 | SBStream sstr; |
| 580 | sb_bp.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 581 | char path[PATH_MAX]; |
| 582 | sb_file_spec->GetPath (path, sizeof(path)); |
| 583 | log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 584 | m_opaque_sp.get(), |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 585 | path, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 586 | line, |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 587 | sb_bp.get(), |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 588 | sstr.GetData()); |
| 589 | } |
| 590 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 591 | return sb_bp; |
| 592 | } |
| 593 | |
| 594 | SBBreakpoint |
| 595 | SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name) |
| 596 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 597 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 598 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | SBBreakpoint sb_bp; |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 600 | if (m_opaque_sp.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 602 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | if (module_name && module_name[0]) |
| 604 | { |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 605 | FileSpecList module_spec_list; |
| 606 | module_spec_list.Append (FileSpec (module_name, false)); |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 607 | *sb_bp = m_opaque_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 608 | } |
| 609 | else |
| 610 | { |
Jim Ingham | 8b7b227 | 2011-10-07 22:23:45 +0000 | [diff] [blame] | 611 | *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | } |
| 613 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 614 | |
| 615 | if (log) |
| 616 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 617 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", |
| 618 | m_opaque_sp.get(), symbol_name, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | return sb_bp; |
| 622 | } |
| 623 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 624 | lldb::SBBreakpoint |
| 625 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 626 | const SBFileSpecList &module_list, |
| 627 | const SBFileSpecList &comp_unit_list) |
| 628 | { |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 629 | uint32_t name_type_mask = eFunctionNameTypeAuto; |
| 630 | return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); |
| 631 | } |
| 632 | |
| 633 | lldb::SBBreakpoint |
| 634 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 635 | uint32_t name_type_mask, |
| 636 | const SBFileSpecList &module_list, |
| 637 | const SBFileSpecList &comp_unit_list) |
| 638 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 639 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 640 | |
| 641 | SBBreakpoint sb_bp; |
| 642 | if (m_opaque_sp.get() && symbol_name && symbol_name[0]) |
| 643 | { |
| 644 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 645 | *sb_bp = m_opaque_sp->CreateBreakpoint (module_list.get(), |
| 646 | comp_unit_list.get(), |
| 647 | symbol_name, |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 648 | name_type_mask, |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 649 | false); |
| 650 | } |
| 651 | |
| 652 | if (log) |
| 653 | { |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 654 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", |
| 655 | m_opaque_sp.get(), symbol_name, name_type_mask, sb_bp.get()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | return sb_bp; |
| 659 | } |
| 660 | |
| 661 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 662 | SBBreakpoint |
| 663 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name) |
| 664 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 665 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 666 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 667 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 668 | if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 670 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | RegularExpression regexp(symbol_name_regex); |
| 672 | |
| 673 | if (module_name && module_name[0]) |
| 674 | { |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 675 | FileSpecList module_spec_list; |
| 676 | module_spec_list.Append (FileSpec (module_name, false)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 678 | *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | } |
| 680 | else |
| 681 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 682 | *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 685 | |
| 686 | if (log) |
| 687 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 688 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
| 689 | m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 | return sb_bp; |
| 693 | } |
| 694 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 695 | lldb::SBBreakpoint |
| 696 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, |
| 697 | const SBFileSpecList &module_list, |
| 698 | const SBFileSpecList &comp_unit_list) |
| 699 | { |
| 700 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 702 | SBBreakpoint sb_bp; |
| 703 | if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) |
| 704 | { |
| 705 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 706 | RegularExpression regexp(symbol_name_regex); |
| 707 | |
| 708 | *sb_bp = m_opaque_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false); |
| 709 | } |
| 710 | |
| 711 | if (log) |
| 712 | { |
| 713 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", |
| 714 | m_opaque_sp.get(), symbol_name_regex, sb_bp.get()); |
| 715 | } |
| 716 | |
| 717 | return sb_bp; |
| 718 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 719 | |
| 720 | SBBreakpoint |
| 721 | SBTarget::BreakpointCreateByAddress (addr_t address) |
| 722 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 723 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 724 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 726 | if (m_opaque_sp.get()) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 727 | { |
| 728 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 729 | *sb_bp = m_opaque_sp->CreateBreakpoint (address, false); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 730 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 731 | |
| 732 | if (log) |
| 733 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 734 | log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", m_opaque_sp.get(), (uint64_t) address, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | return sb_bp; |
| 738 | } |
| 739 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 740 | lldb::SBBreakpoint |
| 741 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name) |
| 742 | { |
| 743 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 744 | |
| 745 | SBBreakpoint sb_bp; |
| 746 | if (m_opaque_sp.get() && source_regex && source_regex[0]) |
| 747 | { |
| 748 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 749 | RegularExpression regexp(source_regex); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 750 | FileSpecList source_file_spec_list; |
| 751 | source_file_spec_list.Append (source_file.ref()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 752 | |
| 753 | if (module_name && module_name[0]) |
| 754 | { |
| 755 | FileSpecList module_spec_list; |
| 756 | module_spec_list.Append (FileSpec (module_name, false)); |
| 757 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 758 | *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 759 | } |
| 760 | else |
| 761 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 762 | *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | if (log) |
| 767 | { |
| 768 | char path[PATH_MAX]; |
| 769 | source_file->GetPath (path, sizeof(path)); |
| 770 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | a253c93 | 2011-09-21 06:45:51 +0000 | [diff] [blame] | 771 | m_opaque_sp.get(), source_regex, path, module_name, sb_bp.get()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | return sb_bp; |
| 775 | } |
| 776 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 777 | lldb::SBBreakpoint |
| 778 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, |
| 779 | const SBFileSpecList &module_list, |
| 780 | const lldb::SBFileSpecList &source_file_list) |
| 781 | { |
| 782 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 783 | |
| 784 | SBBreakpoint sb_bp; |
| 785 | if (m_opaque_sp.get() && source_regex && source_regex[0]) |
| 786 | { |
| 787 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 788 | RegularExpression regexp(source_regex); |
| 789 | *sb_bp = m_opaque_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); |
| 790 | } |
| 791 | |
| 792 | if (log) |
| 793 | { |
| 794 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", |
| 795 | m_opaque_sp.get(), source_regex, sb_bp.get()); |
| 796 | } |
| 797 | |
| 798 | return sb_bp; |
| 799 | } |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 800 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 801 | uint32_t |
| 802 | SBTarget::GetNumBreakpoints () const |
| 803 | { |
| 804 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 805 | { |
| 806 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 807 | return m_opaque_sp->GetBreakpointList().GetSize(); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 808 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | SBBreakpoint |
| 813 | SBTarget::GetBreakpointAtIndex (uint32_t idx) const |
| 814 | { |
| 815 | SBBreakpoint sb_breakpoint; |
| 816 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 817 | { |
| 818 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 819 | *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 820 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 821 | return sb_breakpoint; |
| 822 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 823 | |
| 824 | bool |
| 825 | SBTarget::BreakpointDelete (break_id_t bp_id) |
| 826 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 827 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 828 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 829 | bool result = false; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 830 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 831 | { |
| 832 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 833 | result = m_opaque_sp->RemoveBreakpointByID (bp_id); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 834 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 835 | |
| 836 | if (log) |
| 837 | { |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 838 | log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) bp_id, result); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 844 | SBBreakpoint |
| 845 | SBTarget::FindBreakpointByID (break_id_t bp_id) |
| 846 | { |
| 847 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 848 | |
| 849 | SBBreakpoint sb_breakpoint; |
| 850 | if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID) |
| 851 | { |
| 852 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
| 853 | *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id); |
| 854 | } |
| 855 | |
| 856 | if (log) |
| 857 | { |
| 858 | log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
| 859 | m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); |
| 860 | } |
| 861 | |
| 862 | return sb_breakpoint; |
| 863 | } |
| 864 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 865 | bool |
| 866 | SBTarget::EnableAllBreakpoints () |
| 867 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 868 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 869 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 870 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 871 | m_opaque_sp->EnableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 | return true; |
| 873 | } |
| 874 | return false; |
| 875 | } |
| 876 | |
| 877 | bool |
| 878 | SBTarget::DisableAllBreakpoints () |
| 879 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 880 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 881 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 882 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 883 | m_opaque_sp->DisableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | return true; |
| 885 | } |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | bool |
| 890 | SBTarget::DeleteAllBreakpoints () |
| 891 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 892 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | { |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 894 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 895 | m_opaque_sp->RemoveAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 896 | return true; |
| 897 | } |
| 898 | return false; |
| 899 | } |
| 900 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 901 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 902 | SBTarget::GetNumWatchpoints () const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 903 | { |
| 904 | if (m_opaque_sp) |
| 905 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 906 | // The watchpoint list is thread safe, no need to lock |
| 907 | return m_opaque_sp->GetWatchpointList().GetSize(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 908 | } |
| 909 | return 0; |
| 910 | } |
| 911 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 912 | SBWatchpoint |
| 913 | SBTarget::GetWatchpointAtIndex (uint32_t idx) const |
Johnny Chen | 5eb54bb | 2011-09-27 20:29:45 +0000 | [diff] [blame] | 914 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 915 | SBWatchpoint sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 916 | if (m_opaque_sp) |
| 917 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 918 | // The watchpoint list is thread safe, no need to lock |
| 919 | *sb_watchpoint = m_opaque_sp->GetWatchpointList().GetByIndex(idx); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 920 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 921 | return sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 925 | SBTarget::DeleteWatchpoint (watch_id_t wp_id) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 926 | { |
| 927 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 928 | |
| 929 | bool result = false; |
| 930 | if (m_opaque_sp) |
| 931 | { |
| 932 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 933 | result = m_opaque_sp->RemoveWatchpointByID (wp_id); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | if (log) |
| 937 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 938 | log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", m_opaque_sp.get(), (uint32_t) wp_id, result); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | return result; |
| 942 | } |
| 943 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 944 | SBWatchpoint |
| 945 | SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 946 | { |
| 947 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 948 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 949 | SBWatchpoint sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 950 | if (m_opaque_sp && wp_id != LLDB_INVALID_WATCH_ID) |
| 951 | { |
| 952 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 953 | *sb_watchpoint = m_opaque_sp->GetWatchpointList().FindByID(wp_id); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | if (log) |
| 957 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 958 | log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 959 | m_opaque_sp.get(), (uint32_t) wp_id, sb_watchpoint.get()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 962 | return sb_watchpoint; |
| 963 | } |
| 964 | |
| 965 | lldb::SBWatchpoint |
| 966 | SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write) |
| 967 | { |
| 968 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 969 | |
| 970 | SBWatchpoint sb_watchpoint; |
| 971 | if (m_opaque_sp) |
| 972 | { |
| 973 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 974 | uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) | |
| 975 | (write ? LLDB_WATCH_TYPE_WRITE : 0); |
Johnny Chen | 50e0534 | 2011-10-14 01:16:39 +0000 | [diff] [blame] | 976 | sb_watchpoint = m_opaque_sp->CreateWatchpoint(addr, size, watch_type); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | if (log) |
| 980 | { |
| 981 | log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)", |
| 982 | m_opaque_sp.get(), addr, (uint32_t) size, sb_watchpoint.get()); |
| 983 | } |
| 984 | |
| 985 | return sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 989 | SBTarget::EnableAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 990 | { |
| 991 | if (m_opaque_sp) |
| 992 | { |
| 993 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 994 | m_opaque_sp->EnableAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 995 | return true; |
| 996 | } |
| 997 | return false; |
| 998 | } |
| 999 | |
| 1000 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1001 | SBTarget::DisableAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1002 | { |
| 1003 | if (m_opaque_sp) |
| 1004 | { |
| 1005 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1006 | m_opaque_sp->DisableAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1007 | return true; |
| 1008 | } |
| 1009 | return false; |
| 1010 | } |
| 1011 | |
| 1012 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1013 | SBTarget::DeleteAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1014 | { |
| 1015 | if (m_opaque_sp) |
| 1016 | { |
| 1017 | Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1018 | m_opaque_sp->RemoveAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1019 | return true; |
| 1020 | } |
| 1021 | return false; |
| 1022 | } |
| 1023 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1025 | lldb::SBModule |
| 1026 | SBTarget::AddModule (const char *path, |
| 1027 | const char *triple, |
| 1028 | const char *uuid_cstr) |
| 1029 | { |
| 1030 | lldb::SBModule sb_module; |
| 1031 | if (m_opaque_sp) |
| 1032 | { |
| 1033 | FileSpec module_file_spec; |
| 1034 | UUID module_uuid; |
| 1035 | ArchSpec module_arch; |
| 1036 | |
| 1037 | if (path) |
| 1038 | module_file_spec.SetFile(path, false); |
| 1039 | |
| 1040 | if (uuid_cstr) |
| 1041 | module_uuid.SetfromCString(uuid_cstr); |
| 1042 | |
| 1043 | if (triple) |
| 1044 | module_arch.SetTriple (triple, m_opaque_sp->GetPlatform ().get()); |
| 1045 | |
| 1046 | sb_module.SetModule(m_opaque_sp->GetSharedModule (module_file_spec, |
| 1047 | module_arch, |
| 1048 | uuid_cstr ? &module_uuid : NULL)); |
| 1049 | } |
| 1050 | return sb_module; |
| 1051 | } |
| 1052 | |
| 1053 | bool |
| 1054 | SBTarget::AddModule (lldb::SBModule &module) |
| 1055 | { |
| 1056 | if (m_opaque_sp) |
| 1057 | { |
| 1058 | m_opaque_sp->GetImages().AppendIfNeeded (module.get_sp()); |
| 1059 | return true; |
| 1060 | } |
| 1061 | return false; |
| 1062 | } |
| 1063 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1064 | uint32_t |
| 1065 | SBTarget::GetNumModules () const |
| 1066 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1067 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1068 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1069 | uint32_t num = 0; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1070 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1071 | { |
| 1072 | // The module list is thread safe, no need to lock |
| 1073 | num = m_opaque_sp->GetImages().GetSize(); |
| 1074 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1075 | |
| 1076 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1077 | log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1078 | |
| 1079 | return num; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1082 | void |
| 1083 | SBTarget::Clear () |
| 1084 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1085 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1086 | |
| 1087 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1088 | log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1089 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1090 | m_opaque_sp.reset(); |
| 1091 | } |
| 1092 | |
| 1093 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | SBModule |
| 1095 | SBTarget::FindModule (const SBFileSpec &sb_file_spec) |
| 1096 | { |
| 1097 | SBModule sb_module; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1098 | if (m_opaque_sp && sb_file_spec.IsValid()) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1099 | { |
| 1100 | // The module list is thread safe, no need to lock |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 1101 | sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL)); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1102 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1103 | return sb_module; |
| 1104 | } |
| 1105 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1106 | lldb::ByteOrder |
| 1107 | SBTarget::GetByteOrder () |
| 1108 | { |
| 1109 | if (m_opaque_sp) |
| 1110 | return m_opaque_sp->GetArchitecture().GetByteOrder(); |
| 1111 | return eByteOrderInvalid; |
| 1112 | } |
| 1113 | |
| 1114 | const char * |
| 1115 | SBTarget::GetTriple () |
| 1116 | { |
| 1117 | if (m_opaque_sp) |
| 1118 | { |
| 1119 | std::string triple (m_opaque_sp->GetArchitecture().GetTriple().str()); |
| 1120 | // Unique the string so we don't run into ownership issues since |
| 1121 | // the const strings put the string into the string pool once and |
| 1122 | // the strings never comes out |
| 1123 | ConstString const_triple (triple.c_str()); |
| 1124 | return const_triple.GetCString(); |
| 1125 | } |
| 1126 | return NULL; |
| 1127 | } |
| 1128 | |
| 1129 | uint32_t |
| 1130 | SBTarget::GetAddressByteSize() |
| 1131 | { |
| 1132 | if (m_opaque_sp) |
| 1133 | return m_opaque_sp->GetArchitecture().GetAddressByteSize(); |
| 1134 | return sizeof(void*); |
| 1135 | } |
| 1136 | |
| 1137 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1138 | SBModule |
| 1139 | SBTarget::GetModuleAtIndex (uint32_t idx) |
| 1140 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1141 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1142 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1143 | SBModule sb_module; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1144 | if (m_opaque_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1145 | { |
| 1146 | // The module list is thread safe, no need to lock |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1147 | sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx)); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1148 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1149 | |
| 1150 | if (log) |
| 1151 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1152 | log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
| 1153 | m_opaque_sp.get(), idx, sb_module.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1156 | return sb_module; |
| 1157 | } |
| 1158 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1159 | bool |
| 1160 | SBTarget::RemoveModule (lldb::SBModule module) |
| 1161 | { |
| 1162 | if (m_opaque_sp) |
| 1163 | return m_opaque_sp->GetImages().Remove(module.get_sp()); |
| 1164 | return false; |
| 1165 | } |
| 1166 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1167 | |
| 1168 | SBBroadcaster |
| 1169 | SBTarget::GetBroadcaster () const |
| 1170 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1171 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1172 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1173 | SBBroadcaster broadcaster(m_opaque_sp.get(), false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1174 | |
| 1175 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1176 | log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 1177 | m_opaque_sp.get(), broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1178 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | return broadcaster; |
| 1180 | } |
| 1181 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1182 | |
| 1183 | bool |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1184 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1185 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1186 | Stream &strm = description.ref(); |
| 1187 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1188 | if (m_opaque_sp) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 1189 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1190 | m_opaque_sp->Dump (&strm, description_level); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1191 | } |
| 1192 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1193 | strm.PutCString ("No value"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1194 | |
| 1195 | return true; |
| 1196 | } |
| 1197 | |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1198 | uint32_t |
| 1199 | SBTarget::FindFunctions (const char *name, |
| 1200 | uint32_t name_type_mask, |
| 1201 | bool append, |
| 1202 | lldb::SBSymbolContextList& sc_list) |
| 1203 | { |
| 1204 | if (!append) |
| 1205 | sc_list.Clear(); |
Johnny Chen | cd186e5 | 2011-12-14 01:43:31 +0000 | [diff] [blame] | 1206 | if (name && m_opaque_sp) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1207 | { |
| 1208 | const bool symbols_ok = true; |
| 1209 | return m_opaque_sp->GetImages().FindFunctions (ConstString(name), |
| 1210 | name_type_mask, |
| 1211 | symbols_ok, |
| 1212 | append, |
| 1213 | *sc_list); |
| 1214 | } |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1218 | lldb::SBType |
| 1219 | SBTarget::FindFirstType (const char* type) |
| 1220 | { |
Johnny Chen | cd186e5 | 2011-12-14 01:43:31 +0000 | [diff] [blame] | 1221 | if (type && m_opaque_sp) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1222 | { |
| 1223 | size_t count = m_opaque_sp->GetImages().GetSize(); |
| 1224 | for (size_t idx = 0; idx < count; idx++) |
| 1225 | { |
| 1226 | SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type); |
| 1227 | |
| 1228 | if (found_at_idx.IsValid()) |
| 1229 | return found_at_idx; |
| 1230 | } |
| 1231 | } |
| 1232 | return SBType(); |
| 1233 | } |
| 1234 | |
| 1235 | lldb::SBTypeList |
| 1236 | SBTarget::FindTypes (const char* type) |
| 1237 | { |
| 1238 | |
| 1239 | SBTypeList retval; |
| 1240 | |
Johnny Chen | cd186e5 | 2011-12-14 01:43:31 +0000 | [diff] [blame] | 1241 | if (type && m_opaque_sp) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1242 | { |
| 1243 | ModuleList& images = m_opaque_sp->GetImages(); |
| 1244 | ConstString name_const(type); |
| 1245 | SymbolContext sc; |
| 1246 | TypeList type_list; |
| 1247 | |
| 1248 | uint32_t num_matches = images.FindTypes(sc, |
| 1249 | name_const, |
| 1250 | true, |
| 1251 | UINT32_MAX, |
| 1252 | type_list); |
| 1253 | |
| 1254 | for (size_t idx = 0; idx < num_matches; idx++) |
| 1255 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 1256 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 1257 | if (type_sp) |
| 1258 | retval.Append(SBType(type_sp)); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | return retval; |
| 1262 | } |
| 1263 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1264 | SBValueList |
| 1265 | SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) |
| 1266 | { |
| 1267 | SBValueList sb_value_list; |
| 1268 | |
Johnny Chen | cd186e5 | 2011-12-14 01:43:31 +0000 | [diff] [blame] | 1269 | if (name && m_opaque_sp) |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1270 | { |
| 1271 | VariableList variable_list; |
| 1272 | const bool append = true; |
| 1273 | const uint32_t match_count = m_opaque_sp->GetImages().FindGlobalVariables (ConstString (name), |
| 1274 | append, |
| 1275 | max_matches, |
| 1276 | variable_list); |
| 1277 | |
| 1278 | if (match_count > 0) |
| 1279 | { |
| 1280 | ExecutionContextScope *exe_scope = m_opaque_sp->GetProcessSP().get(); |
| 1281 | if (exe_scope == NULL) |
| 1282 | exe_scope = m_opaque_sp.get(); |
| 1283 | ValueObjectList &value_object_list = sb_value_list.ref(); |
| 1284 | for (uint32_t i=0; i<match_count; ++i) |
| 1285 | { |
| 1286 | lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); |
| 1287 | if (valobj_sp) |
| 1288 | value_object_list.Append(valobj_sp); |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | return sb_value_list; |
| 1294 | } |
| 1295 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 1296 | SBSourceManager |
| 1297 | SBTarget::GetSourceManager() |
| 1298 | { |
| 1299 | SBSourceManager source_manager (*this); |
| 1300 | return source_manager; |
| 1301 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1302 | |
Sean Callanan | ef1f690 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 1303 | lldb::SBInstructionList |
| 1304 | SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) |
| 1305 | { |
| 1306 | SBInstructionList sb_instructions; |
| 1307 | |
| 1308 | if (m_opaque_sp) |
| 1309 | { |
| 1310 | Address addr; |
| 1311 | |
| 1312 | if (base_addr.get()) |
| 1313 | addr = *base_addr.get(); |
| 1314 | |
| 1315 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (m_opaque_sp->GetArchitecture(), |
| 1316 | NULL, |
| 1317 | addr, |
| 1318 | buf, |
| 1319 | size)); |
| 1320 | } |
| 1321 | |
| 1322 | return sb_instructions; |
| 1323 | } |
| 1324 | |
| 1325 | lldb::SBInstructionList |
| 1326 | SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) |
| 1327 | { |
| 1328 | return GetInstructions (ResolveLoadAddress(base_addr), buf, size); |
| 1329 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1330 | |
| 1331 | SBError |
| 1332 | SBTarget::SetSectionLoadAddress (lldb::SBSection section, |
| 1333 | lldb::addr_t section_base_addr) |
| 1334 | { |
| 1335 | SBError sb_error; |
| 1336 | |
| 1337 | if (IsValid()) |
| 1338 | { |
| 1339 | if (!section.IsValid()) |
| 1340 | { |
| 1341 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 1342 | } |
| 1343 | else |
| 1344 | { |
| 1345 | m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSection(), section_base_addr); |
| 1346 | } |
| 1347 | } |
| 1348 | else |
| 1349 | { |
| 1350 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1351 | } |
| 1352 | return sb_error; |
| 1353 | } |
| 1354 | |
| 1355 | SBError |
| 1356 | SBTarget::ClearSectionLoadAddress (lldb::SBSection section) |
| 1357 | { |
| 1358 | SBError sb_error; |
| 1359 | |
| 1360 | if (IsValid()) |
| 1361 | { |
| 1362 | if (!section.IsValid()) |
| 1363 | { |
| 1364 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 1365 | } |
| 1366 | else |
| 1367 | { |
| 1368 | m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSection()); |
| 1369 | } |
| 1370 | } |
| 1371 | else |
| 1372 | { |
| 1373 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1374 | } |
| 1375 | return sb_error; |
| 1376 | } |
| 1377 | |
| 1378 | SBError |
| 1379 | SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) |
| 1380 | { |
| 1381 | SBError sb_error; |
| 1382 | |
| 1383 | char path[PATH_MAX]; |
| 1384 | if (IsValid()) |
| 1385 | { |
| 1386 | if (!module.IsValid()) |
| 1387 | { |
| 1388 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 1389 | } |
| 1390 | else |
| 1391 | { |
| 1392 | ObjectFile *objfile = module->GetObjectFile(); |
| 1393 | if (objfile) |
| 1394 | { |
| 1395 | SectionList *section_list = objfile->GetSectionList(); |
| 1396 | if (section_list) |
| 1397 | { |
| 1398 | const size_t num_sections = section_list->GetSize(); |
| 1399 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1400 | { |
| 1401 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 1402 | if (section_sp) |
| 1403 | m_opaque_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); |
| 1404 | } |
| 1405 | } |
| 1406 | else |
| 1407 | { |
| 1408 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 1409 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 1410 | } |
| 1411 | } |
| 1412 | else |
| 1413 | { |
| 1414 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 1415 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | else |
| 1420 | { |
| 1421 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1422 | } |
| 1423 | return sb_error; |
| 1424 | } |
| 1425 | |
| 1426 | SBError |
| 1427 | SBTarget::ClearModuleLoadAddress (lldb::SBModule module) |
| 1428 | { |
| 1429 | SBError sb_error; |
| 1430 | |
| 1431 | char path[PATH_MAX]; |
| 1432 | if (IsValid()) |
| 1433 | { |
| 1434 | if (!module.IsValid()) |
| 1435 | { |
| 1436 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 1437 | } |
| 1438 | else |
| 1439 | { |
| 1440 | ObjectFile *objfile = module->GetObjectFile(); |
| 1441 | if (objfile) |
| 1442 | { |
| 1443 | SectionList *section_list = objfile->GetSectionList(); |
| 1444 | if (section_list) |
| 1445 | { |
| 1446 | const size_t num_sections = section_list->GetSize(); |
| 1447 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1448 | { |
| 1449 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 1450 | if (section_sp) |
| 1451 | m_opaque_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); |
| 1452 | } |
| 1453 | } |
| 1454 | else |
| 1455 | { |
| 1456 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 1457 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 1458 | } |
| 1459 | } |
| 1460 | else |
| 1461 | { |
| 1462 | module->GetFileSpec().GetPath (path, sizeof(path)); |
| 1463 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | else |
| 1468 | { |
| 1469 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1470 | } |
| 1471 | return sb_error; |
| 1472 | } |
| 1473 | |
| 1474 | |