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