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