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 | |
| 12 | #include "lldb/lldb-include.h" |
| 13 | |
| 14 | #include "lldb/API/SBFileSpec.h" |
| 15 | #include "lldb/API/SBModule.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/BreakpointID.h" |
| 18 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 19 | #include "lldb/Breakpoint/BreakpointList.h" |
| 20 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 21 | #include "lldb/Core/Address.h" |
| 22 | #include "lldb/Core/AddressResolver.h" |
| 23 | #include "lldb/Core/AddressResolverName.h" |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Core/ArchSpec.h" |
| 26 | #include "lldb/Core/Debugger.h" |
| 27 | #include "lldb/Core/Disassembler.h" |
| 28 | #include "lldb/Core/FileSpec.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 29 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/RegularExpression.h" |
| 31 | #include "lldb/Core/SearchFilter.h" |
| 32 | #include "lldb/Core/STLUtils.h" |
| 33 | #include "lldb/Target/Process.h" |
| 34 | #include "lldb/Target/Target.h" |
| 35 | #include "lldb/Target/TargetList.h" |
| 36 | |
| 37 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 38 | #include "../source/Commands/CommandObjectBreakpoint.h" |
| 39 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 40 | #include "lldb/API/SBDebugger.h" |
| 41 | #include "lldb/API/SBProcess.h" |
| 42 | #include "lldb/API/SBListener.h" |
| 43 | #include "lldb/API/SBBreakpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | |
| 45 | using namespace lldb; |
| 46 | using namespace lldb_private; |
| 47 | |
| 48 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 49 | |
| 50 | //---------------------------------------------------------------------- |
| 51 | // SBTarget constructor |
| 52 | //---------------------------------------------------------------------- |
| 53 | SBTarget::SBTarget () |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | SBTarget::SBTarget (const SBTarget& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 58 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
| 60 | } |
| 61 | |
| 62 | SBTarget::SBTarget(const TargetSP& target_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 63 | m_opaque_sp (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | { |
| 65 | } |
| 66 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | //---------------------------------------------------------------------- |
| 68 | // Destructor |
| 69 | //---------------------------------------------------------------------- |
| 70 | SBTarget::~SBTarget() |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | bool |
| 75 | SBTarget::IsValid () const |
| 76 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 77 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | SBProcess |
| 81 | SBTarget::GetProcess () |
| 82 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | SBProcess sb_process; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 85 | if (m_opaque_sp) |
| 86 | sb_process.SetProcess (m_opaque_sp->GetProcessSP()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 87 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 88 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 89 | if (log) |
| 90 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 91 | log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
| 92 | m_opaque_sp.get(), sb_process.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | return sb_process; |
| 96 | } |
| 97 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 98 | SBDebugger |
| 99 | SBTarget::GetDebugger () const |
| 100 | { |
| 101 | SBDebugger debugger; |
| 102 | if (m_opaque_sp) |
| 103 | debugger.reset (m_opaque_sp->GetDebugger().GetSP()); |
| 104 | return debugger; |
| 105 | } |
| 106 | |
Greg Clayton | 992ce26 | 2010-10-06 18:44:26 +0000 | [diff] [blame] | 107 | |
| 108 | // DEPRECATED |
| 109 | SBProcess |
| 110 | SBTarget::CreateProcess () |
| 111 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 112 | |
Greg Clayton | 992ce26 | 2010-10-06 18:44:26 +0000 | [diff] [blame] | 113 | SBProcess sb_process; |
| 114 | |
| 115 | if (m_opaque_sp) |
| 116 | sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); |
| 117 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 118 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 119 | if (log) |
| 120 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 121 | log->Printf ("SBTarget(%p)::CreateProcess () => SBProcess(%p)", |
| 122 | m_opaque_sp.get(), sb_process.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Greg Clayton | 992ce26 | 2010-10-06 18:44:26 +0000 | [diff] [blame] | 125 | return sb_process; |
| 126 | } |
| 127 | |
| 128 | |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 129 | SBProcess |
| 130 | SBTarget::LaunchProcess |
| 131 | ( |
| 132 | char const **argv, |
| 133 | char const **envp, |
| 134 | const char *tty, |
| 135 | uint32_t launch_flags, |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 136 | bool stop_at_entry |
| 137 | ) |
| 138 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 139 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 140 | |
| 141 | if (log) |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 142 | log->Printf ("SBTarget(%p)::LaunchProcess (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i)", |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 143 | m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 144 | |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 145 | SBError sb_error; |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 146 | SBProcess sb_process = Launch (argv, envp, tty, launch_flags, stop_at_entry, sb_error); |
| 147 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 148 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 149 | if (log) |
| 150 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 151 | log->Printf ("SBTarget(%p)::LaunchProcess (...) => SBProcess(%p)", |
| 152 | m_opaque_sp.get(), sb_process.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | return sb_process; |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | SBProcess |
| 159 | SBTarget::Launch |
| 160 | ( |
| 161 | char const **argv, |
| 162 | char const **envp, |
| 163 | const char *tty, |
| 164 | uint32_t launch_flags, |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 165 | bool stop_at_entry, |
| 166 | SBError &error |
| 167 | ) |
| 168 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 169 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 170 | |
| 171 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 172 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 173 | log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i, &error (%p))...", |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 174 | m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry, error.get()); |
| 175 | } |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 176 | SBProcess sb_process; |
| 177 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 178 | { |
Greg Clayton | 992ce26 | 2010-10-06 18:44:26 +0000 | [diff] [blame] | 179 | // DEPRECATED, this will change when CreateProcess is removed... |
| 180 | if (m_opaque_sp->GetProcessSP()) |
| 181 | { |
| 182 | sb_process.SetProcess(m_opaque_sp->GetProcessSP()); |
| 183 | } |
| 184 | else |
| 185 | { |
| 186 | // When launching, we always want to create a new process When |
| 187 | // SBTarget::CreateProcess is removed, this will always happen. |
| 188 | sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); |
| 189 | } |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 190 | |
| 191 | if (sb_process.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | { |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 193 | error.SetError (sb_process->Launch (argv, envp, launch_flags, tty, tty, tty)); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 194 | if (error.Success()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 195 | { |
Sean Callanan | 451ee7c | 2010-10-07 22:51:14 +0000 | [diff] [blame] | 196 | // We we are stopping at the entry point, we can return now! |
| 197 | if (stop_at_entry) |
| 198 | return sb_process; |
| 199 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 200 | // Make sure we are stopped at the entry |
| 201 | StateType state = sb_process->WaitForProcessToStop (NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | if (state == eStateStopped) |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 203 | { |
| 204 | // resume the process to skip the entry point |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 205 | error.SetError (sb_process->Resume()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 206 | if (error.Success()) |
| 207 | { |
| 208 | // If we are doing synchronous mode, then wait for the |
| 209 | // process to stop yet again! |
| 210 | if (m_opaque_sp->GetDebugger().GetAsyncExecution () == false) |
| 211 | sb_process->WaitForProcessToStop (NULL); |
| 212 | } |
| 213 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 216 | else |
| 217 | { |
| 218 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 219 | } |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | error.SetErrorString ("SBTarget is invalid"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 224 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 225 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 226 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 227 | if (log) |
| 228 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 229 | log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", |
| 230 | m_opaque_sp.get(), sb_process.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 233 | return sb_process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 236 | |
| 237 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 238 | SBTarget::AttachToProcessWithID |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 239 | ( |
| 240 | lldb::pid_t pid,// The process ID to attach to |
| 241 | SBError& error // An error explaining what went wrong if attach fails |
| 242 | ) |
| 243 | { |
| 244 | SBProcess sb_process; |
| 245 | if (m_opaque_sp) |
| 246 | { |
| 247 | // DEPRECATED, this will change when CreateProcess is removed... |
| 248 | if (m_opaque_sp->GetProcessSP()) |
| 249 | { |
| 250 | sb_process.SetProcess(m_opaque_sp->GetProcessSP()); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | // When launching, we always want to create a new process When |
| 255 | // SBTarget::CreateProcess is removed, this will always happen. |
| 256 | sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); |
| 257 | } |
| 258 | |
| 259 | if (sb_process.IsValid()) |
| 260 | { |
| 261 | error.SetError (sb_process->Attach (pid)); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | error.SetErrorString ("SBTarget is invalid"); |
| 271 | } |
| 272 | return sb_process; |
| 273 | |
| 274 | } |
| 275 | |
| 276 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 277 | SBTarget::AttachToProcessWithName |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 278 | ( |
| 279 | const char *name, // basename of process to attach to |
| 280 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 281 | SBError& error // An error explaining what went wrong if attach fails |
| 282 | ) |
| 283 | { |
| 284 | SBProcess sb_process; |
| 285 | if (m_opaque_sp) |
| 286 | { |
| 287 | // DEPRECATED, this will change when CreateProcess is removed... |
| 288 | if (m_opaque_sp->GetProcessSP()) |
| 289 | { |
| 290 | sb_process.SetProcess(m_opaque_sp->GetProcessSP()); |
| 291 | } |
| 292 | else |
| 293 | { |
| 294 | // When launching, we always want to create a new process When |
| 295 | // SBTarget::CreateProcess is removed, this will always happen. |
| 296 | sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); |
| 297 | } |
| 298 | |
| 299 | if (sb_process.IsValid()) |
| 300 | { |
| 301 | error.SetError (sb_process->Attach (name, wait_for)); |
| 302 | } |
| 303 | else |
| 304 | { |
| 305 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 306 | } |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | error.SetErrorString ("SBTarget is invalid"); |
| 311 | } |
| 312 | return sb_process; |
| 313 | |
| 314 | } |
| 315 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | SBFileSpec |
| 317 | SBTarget::GetExecutable () |
| 318 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 319 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 320 | SBFileSpec exe_file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 321 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 322 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 323 | ModuleSP exe_module_sp (m_opaque_sp->GetExecutableModule ()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | if (exe_module_sp) |
| 325 | exe_file_spec.SetFileSpec (exe_module_sp->GetFileSpec()); |
| 326 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 327 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 328 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 329 | if (log) |
| 330 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 331 | log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
| 332 | m_opaque_sp.get(), exe_file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | return exe_file_spec; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | bool |
| 340 | SBTarget::DeleteTargetFromList (TargetList *list) |
| 341 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 342 | if (m_opaque_sp) |
| 343 | return list->DeleteTarget (m_opaque_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | else |
| 345 | return false; |
| 346 | } |
| 347 | |
| 348 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | SBTarget::operator == (const SBTarget &rhs) const |
| 350 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 351 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | bool |
| 355 | SBTarget::operator != (const SBTarget &rhs) const |
| 356 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 357 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | lldb_private::Target * |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 361 | SBTarget::operator ->() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 362 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 363 | return m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | } |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 365 | |
| 366 | lldb_private::Target * |
| 367 | SBTarget::get() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 369 | return m_opaque_sp.get(); |
| 370 | } |
| 371 | |
| 372 | void |
| 373 | SBTarget::reset (const lldb::TargetSP& target_sp) |
| 374 | { |
| 375 | m_opaque_sp = target_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | SBBreakpoint |
| 379 | SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line) |
| 380 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 381 | return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file), line)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | SBBreakpoint |
| 385 | SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line) |
| 386 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 387 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 388 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 390 | if (m_opaque_sp.get() && line != 0) |
| 391 | *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 392 | |
| 393 | if (log) |
| 394 | { |
| 395 | SBStream sstr; |
| 396 | sb_bp.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 397 | char path[PATH_MAX]; |
| 398 | sb_file_spec->GetPath (path, sizeof(path)); |
| 399 | log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 400 | m_opaque_sp.get(), |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 401 | path, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 402 | line, |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 403 | sb_bp.get(), |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 404 | sstr.GetData()); |
| 405 | } |
| 406 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | return sb_bp; |
| 408 | } |
| 409 | |
| 410 | SBBreakpoint |
| 411 | SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name) |
| 412 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 413 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 414 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 416 | if (m_opaque_sp.get() && symbol_name && symbol_name[0]) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | { |
| 418 | if (module_name && module_name[0]) |
| 419 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 420 | FileSpec module_file_spec(module_name, false); |
Jim Ingham | 7ec03bd | 2010-09-30 21:21:43 +0000 | [diff] [blame] | 421 | *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | } |
| 423 | else |
| 424 | { |
Jim Ingham | 7ec03bd | 2010-09-30 21:21:43 +0000 | [diff] [blame] | 425 | *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, symbol_name, eFunctionNameTypeFull | eFunctionNameTypeBase, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 428 | |
| 429 | if (log) |
| 430 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 431 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", |
| 432 | m_opaque_sp.get(), symbol_name, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | return sb_bp; |
| 436 | } |
| 437 | |
| 438 | SBBreakpoint |
| 439 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name) |
| 440 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 441 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 442 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 444 | if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 445 | { |
| 446 | RegularExpression regexp(symbol_name_regex); |
| 447 | |
| 448 | if (module_name && module_name[0]) |
| 449 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 450 | FileSpec module_file_spec(module_name, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 452 | *sb_bp = m_opaque_sp->CreateBreakpoint (&module_file_spec, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | } |
| 454 | else |
| 455 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 456 | *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 459 | |
| 460 | if (log) |
| 461 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 462 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
| 463 | m_opaque_sp.get(), symbol_name_regex, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | return sb_bp; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | |
| 471 | SBBreakpoint |
| 472 | SBTarget::BreakpointCreateByAddress (addr_t address) |
| 473 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 474 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 475 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | SBBreakpoint sb_bp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 477 | if (m_opaque_sp.get()) |
| 478 | *sb_bp = m_opaque_sp->CreateBreakpoint (address, false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 479 | |
| 480 | if (log) |
| 481 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 482 | log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (%p, address=%p) => SBBreakpoint(%p)", m_opaque_sp.get(), address, sb_bp.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 sb_bp; |
| 486 | } |
| 487 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 488 | SBBreakpoint |
| 489 | SBTarget::FindBreakpointByID (break_id_t bp_id) |
| 490 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 491 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 492 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | SBBreakpoint sb_breakpoint; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 494 | if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID) |
| 495 | *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 496 | |
| 497 | if (log) |
| 498 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 499 | log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
| 500 | m_opaque_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | return sb_breakpoint; |
| 504 | } |
| 505 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 506 | uint32_t |
| 507 | SBTarget::GetNumBreakpoints () const |
| 508 | { |
| 509 | if (m_opaque_sp) |
| 510 | return m_opaque_sp->GetBreakpointList().GetSize(); |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | SBBreakpoint |
| 515 | SBTarget::GetBreakpointAtIndex (uint32_t idx) const |
| 516 | { |
| 517 | SBBreakpoint sb_breakpoint; |
| 518 | if (m_opaque_sp) |
| 519 | *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
| 520 | return sb_breakpoint; |
| 521 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | |
| 523 | bool |
| 524 | SBTarget::BreakpointDelete (break_id_t bp_id) |
| 525 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 526 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 527 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 528 | bool result = false; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 529 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 530 | result = m_opaque_sp->RemoveBreakpointByID (bp_id); |
| 531 | |
| 532 | if (log) |
| 533 | { |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 534 | 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] | 535 | } |
| 536 | |
| 537 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | bool |
| 541 | SBTarget::EnableAllBreakpoints () |
| 542 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 543 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 544 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 545 | m_opaque_sp->EnableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | return true; |
| 547 | } |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | bool |
| 552 | SBTarget::DisableAllBreakpoints () |
| 553 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 554 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 555 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 556 | m_opaque_sp->DisableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | return true; |
| 558 | } |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | bool |
| 563 | SBTarget::DeleteAllBreakpoints () |
| 564 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 565 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 567 | m_opaque_sp->RemoveAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | return true; |
| 569 | } |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | |
| 574 | uint32_t |
| 575 | SBTarget::GetNumModules () const |
| 576 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 577 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 578 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 579 | uint32_t num = 0; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 580 | if (m_opaque_sp) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 581 | num = m_opaque_sp->GetImages().GetSize(); |
| 582 | |
| 583 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 584 | log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 585 | |
| 586 | return num; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 589 | void |
| 590 | SBTarget::Clear () |
| 591 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 592 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 593 | |
| 594 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 595 | log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 596 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 597 | m_opaque_sp.reset(); |
| 598 | } |
| 599 | |
| 600 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | SBModule |
| 602 | SBTarget::FindModule (const SBFileSpec &sb_file_spec) |
| 603 | { |
| 604 | SBModule sb_module; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 605 | if (m_opaque_sp && sb_file_spec.IsValid()) |
| 606 | sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 607 | return sb_module; |
| 608 | } |
| 609 | |
| 610 | SBModule |
| 611 | SBTarget::GetModuleAtIndex (uint32_t idx) |
| 612 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 613 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 614 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | SBModule sb_module; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 616 | if (m_opaque_sp) |
| 617 | sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 618 | |
| 619 | if (log) |
| 620 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 621 | log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
| 622 | m_opaque_sp.get(), idx, sb_module.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | return sb_module; |
| 626 | } |
| 627 | |
| 628 | |
| 629 | SBBroadcaster |
| 630 | SBTarget::GetBroadcaster () const |
| 631 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 632 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 633 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 634 | SBBroadcaster broadcaster(m_opaque_sp.get(), false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 635 | |
| 636 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 637 | log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 638 | m_opaque_sp.get(), broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 639 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | return broadcaster; |
| 641 | } |
| 642 | |
| 643 | void |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 644 | SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const char *module_name) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 645 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 646 | if (start_addr == LLDB_INVALID_ADDRESS) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 647 | return; |
| 648 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 649 | FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 650 | if (out == NULL) |
| 651 | return; |
| 652 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 653 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 655 | ModuleSP module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 656 | if (module_name != NULL) |
| 657 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 658 | FileSpec module_file_spec (module_name, false); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 659 | module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 660 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 661 | |
| 662 | AddressRange range; |
| 663 | |
| 664 | // Make sure the process object is alive if we have one (it might be |
| 665 | // created but we might not be launched yet). |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 666 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 667 | Process *sb_process = m_opaque_sp->GetProcessSP().get(); |
| 668 | if (sb_process && !sb_process->IsAlive()) |
| 669 | sb_process = NULL; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 670 | |
| 671 | // If we are given a module, then "start_addr" is a file address in |
| 672 | // that module. |
| 673 | if (module_sp) |
| 674 | { |
| 675 | if (!module_sp->ResolveFileAddress (start_addr, range.GetBaseAddress())) |
| 676 | range.GetBaseAddress().SetOffset(start_addr); |
| 677 | } |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 678 | else if (m_opaque_sp->GetSectionLoadList().IsEmpty() == false) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 679 | { |
| 680 | // We don't have a module, se we need to figure out if "start_addr" |
| 681 | // resolves to anything in a running process. |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 682 | if (!m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (start_addr, range.GetBaseAddress())) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 683 | range.GetBaseAddress().SetOffset(start_addr); |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | if (m_opaque_sp->GetImages().ResolveFileAddress (start_addr, range.GetBaseAddress())) |
| 688 | range.GetBaseAddress().SetOffset(start_addr); |
| 689 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | |
| 691 | // For now, we need a process; the disassembly functions insist. If we don't have one already, |
| 692 | // make one. |
| 693 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 694 | ExecutionContext exe_ctx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 695 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 696 | if (sb_process) |
| 697 | sb_process->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 698 | else |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 699 | m_opaque_sp->CalculateExecutionContext(exe_ctx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 700 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 701 | if (end_addr == LLDB_INVALID_ADDRESS || end_addr < start_addr) |
| 702 | range.SetByteSize( DEFAULT_DISASM_BYTE_SIZE); |
| 703 | else |
| 704 | range.SetByteSize(end_addr - start_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 706 | StreamFile out_stream (out); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 707 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 708 | Disassembler::Disassemble (m_opaque_sp->GetDebugger(), |
| 709 | m_opaque_sp->GetArchitecture(), |
| 710 | exe_ctx, |
| 711 | range, |
| 712 | 3, |
| 713 | false, |
| 714 | out_stream); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
| 718 | void |
| 719 | SBTarget::Disassemble (const char *function_name, const char *module_name) |
| 720 | { |
| 721 | if (function_name == NULL) |
| 722 | return; |
| 723 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 724 | FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | if (out == NULL) |
| 726 | return; |
| 727 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 728 | if (m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 729 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 730 | Disassembler *disassembler = Disassembler::FindPlugin (m_opaque_sp->GetArchitecture()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 731 | if (disassembler == NULL) |
| 732 | return; |
| 733 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 734 | ModuleSP module_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | if (module_name != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 736 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 737 | FileSpec module_file_spec (module_name, false); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 738 | module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 740 | |
| 741 | ExecutionContext exe_ctx; |
| 742 | |
| 743 | // Make sure the process object is alive if we have one (it might be |
| 744 | // created but we might not be launched yet). |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 745 | Process *sb_process = m_opaque_sp->GetProcessSP().get(); |
| 746 | if (sb_process && !sb_process->IsAlive()) |
| 747 | sb_process = NULL; |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 748 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 749 | if (sb_process) |
| 750 | sb_process->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 751 | else |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 752 | m_opaque_sp->CalculateExecutionContext(exe_ctx); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 753 | |
| 754 | |
| 755 | StreamFile out_stream (out); |
| 756 | |
| 757 | Disassembler::Disassemble (m_opaque_sp->GetDebugger(), |
| 758 | m_opaque_sp->GetArchitecture(), |
| 759 | exe_ctx, |
| 760 | ConstString (function_name), |
| 761 | module_sp.get(), |
| 762 | 3, |
| 763 | false, |
| 764 | out_stream); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 765 | } |
| 766 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 767 | |
| 768 | bool |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 769 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 770 | { |
| 771 | if (m_opaque_sp) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 772 | { |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 773 | description.ref(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 774 | m_opaque_sp->Dump (description.get(), description_level); |
| 775 | } |
| 776 | else |
| 777 | description.Printf ("No value"); |
| 778 | |
| 779 | return true; |
| 780 | } |
| 781 | |
| 782 | bool |
| 783 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) const |
| 784 | { |
| 785 | if (m_opaque_sp) |
| 786 | { |
| 787 | description.ref(); |
| 788 | m_opaque_sp->Dump (description.get(), description_level); |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 789 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 790 | else |
| 791 | description.Printf ("No value"); |
| 792 | |
| 793 | return true; |
| 794 | } |