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