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