Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBTarget.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 7a62c8b | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBTarget.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-public.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBDebugger.h" |
| 15 | #include "lldb/API/SBBreakpoint.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 17 | #include "lldb/API/SBListener.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBModule.h" |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBSourceManager.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBProcess.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBStream.h" |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Breakpoint/BreakpointID.h" |
| 24 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 25 | #include "lldb/Breakpoint/BreakpointList.h" |
| 26 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 27 | #include "lldb/Core/Address.h" |
| 28 | #include "lldb/Core/AddressResolver.h" |
| 29 | #include "lldb/Core/AddressResolverName.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Core/ArchSpec.h" |
| 31 | #include "lldb/Core/Debugger.h" |
| 32 | #include "lldb/Core/Disassembler.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 33 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/RegularExpression.h" |
| 35 | #include "lldb/Core/SearchFilter.h" |
| 36 | #include "lldb/Core/STLUtils.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 37 | #include "lldb/Core/ValueObjectList.h" |
| 38 | #include "lldb/Core/ValueObjectVariable.h" |
| 39 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 40 | #include "lldb/Host/Host.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 41 | #include "lldb/Interpreter/Args.h" |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | #include "lldb/Target/Process.h" |
| 45 | #include "lldb/Target/Target.h" |
| 46 | #include "lldb/Target/TargetList.h" |
| 47 | |
| 48 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 49 | #include "../source/Commands/CommandObjectBreakpoint.h" |
| 50 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
| 52 | using namespace lldb; |
| 53 | using namespace lldb_private; |
| 54 | |
| 55 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 56 | |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 57 | SBLaunchInfo::SBLaunchInfo (const char **argv) : |
| 58 | m_opaque_sp(new ProcessLaunchInfo()) |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 59 | { |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 60 | m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR); |
| 61 | if (argv && argv[0]) |
| 62 | m_opaque_sp->GetArguments().SetArguments(argv); |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | uint32_t |
| 66 | SBLaunchInfo::GetUserID() |
| 67 | { |
| 68 | return m_opaque_sp->GetUserID(); |
| 69 | } |
| 70 | |
| 71 | uint32_t |
| 72 | SBLaunchInfo::GetGroupID() |
| 73 | { |
| 74 | return m_opaque_sp->GetGroupID(); |
| 75 | } |
| 76 | |
| 77 | bool |
| 78 | SBLaunchInfo::UserIDIsValid () |
| 79 | { |
| 80 | return m_opaque_sp->UserIDIsValid(); |
| 81 | } |
| 82 | |
| 83 | bool |
| 84 | SBLaunchInfo::GroupIDIsValid () |
| 85 | { |
| 86 | return m_opaque_sp->GroupIDIsValid(); |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | SBLaunchInfo::SetUserID (uint32_t uid) |
| 91 | { |
| 92 | m_opaque_sp->SetUserID (uid); |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | SBLaunchInfo::SetGroupID (uint32_t gid) |
| 97 | { |
| 98 | m_opaque_sp->SetGroupID (gid); |
| 99 | } |
| 100 | |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 101 | uint32_t |
| 102 | SBLaunchInfo::GetNumArguments () |
| 103 | { |
| 104 | return m_opaque_sp->GetArguments().GetArgumentCount(); |
| 105 | } |
| 106 | |
| 107 | const char * |
| 108 | SBLaunchInfo::GetArgumentAtIndex (uint32_t idx) |
| 109 | { |
| 110 | return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | SBLaunchInfo::SetArguments (const char **argv, bool append) |
| 115 | { |
| 116 | if (append) |
| 117 | { |
| 118 | if (argv) |
| 119 | m_opaque_sp->GetArguments().AppendArguments(argv); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | if (argv) |
| 124 | m_opaque_sp->GetArguments().SetArguments(argv); |
| 125 | else |
| 126 | m_opaque_sp->GetArguments().Clear(); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | uint32_t |
| 131 | SBLaunchInfo::GetNumEnvironmentEntries () |
| 132 | { |
| 133 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); |
| 134 | } |
| 135 | |
| 136 | const char * |
| 137 | SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx) |
| 138 | { |
| 139 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); |
| 140 | } |
| 141 | |
| 142 | void |
| 143 | SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append) |
| 144 | { |
| 145 | if (append) |
| 146 | { |
| 147 | if (envp) |
| 148 | m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | if (envp) |
| 153 | m_opaque_sp->GetEnvironmentEntries().SetArguments(envp); |
| 154 | else |
| 155 | m_opaque_sp->GetEnvironmentEntries().Clear(); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | void |
| 160 | SBLaunchInfo::Clear () |
| 161 | { |
| 162 | m_opaque_sp->Clear(); |
| 163 | } |
| 164 | |
| 165 | const char * |
| 166 | SBLaunchInfo::GetWorkingDirectory () const |
| 167 | { |
| 168 | return m_opaque_sp->GetWorkingDirectory(); |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | SBLaunchInfo::SetWorkingDirectory (const char *working_dir) |
| 173 | { |
| 174 | m_opaque_sp->SetWorkingDirectory(working_dir); |
| 175 | } |
| 176 | |
| 177 | uint32_t |
| 178 | SBLaunchInfo::GetLaunchFlags () |
| 179 | { |
| 180 | return m_opaque_sp->GetFlags().Get(); |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | SBLaunchInfo::SetLaunchFlags (uint32_t flags) |
| 185 | { |
| 186 | m_opaque_sp->GetFlags().Reset(flags); |
| 187 | } |
| 188 | |
| 189 | const char * |
| 190 | SBLaunchInfo::GetProcessPluginName () |
| 191 | { |
| 192 | return m_opaque_sp->GetProcessPluginName(); |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | SBLaunchInfo::SetProcessPluginName (const char *plugin_name) |
| 197 | { |
| 198 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 199 | } |
| 200 | |
| 201 | const char * |
| 202 | SBLaunchInfo::GetShell () |
| 203 | { |
| 204 | return m_opaque_sp->GetShell(); |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | SBLaunchInfo::SetShell (const char * path) |
| 209 | { |
| 210 | m_opaque_sp->SetShell (path); |
| 211 | } |
| 212 | |
| 213 | uint32_t |
| 214 | SBLaunchInfo::GetResumeCount () |
| 215 | { |
| 216 | return m_opaque_sp->GetResumeCount(); |
| 217 | } |
| 218 | |
| 219 | void |
| 220 | SBLaunchInfo::SetResumeCount (uint32_t c) |
| 221 | { |
| 222 | m_opaque_sp->SetResumeCount (c); |
| 223 | } |
| 224 | |
| 225 | bool |
| 226 | SBLaunchInfo::AddCloseFileAction (int fd) |
| 227 | { |
| 228 | return m_opaque_sp->AppendCloseFileAction(fd); |
| 229 | } |
| 230 | |
| 231 | bool |
| 232 | SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd) |
| 233 | { |
| 234 | return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); |
| 235 | } |
| 236 | |
| 237 | bool |
| 238 | SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write) |
| 239 | { |
| 240 | return m_opaque_sp->AppendOpenFileAction(fd, path, read, write); |
| 241 | } |
| 242 | |
| 243 | bool |
| 244 | SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write) |
| 245 | { |
| 246 | return m_opaque_sp->AppendSuppressFileAction(fd, read, write); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | SBAttachInfo::SBAttachInfo () : |
| 251 | m_opaque_sp (new ProcessAttachInfo()) |
| 252 | { |
| 253 | } |
| 254 | |
| 255 | SBAttachInfo::SBAttachInfo (lldb::pid_t pid) : |
| 256 | m_opaque_sp (new ProcessAttachInfo()) |
| 257 | { |
| 258 | m_opaque_sp->SetProcessID (pid); |
| 259 | } |
| 260 | |
| 261 | SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) : |
| 262 | m_opaque_sp (new ProcessAttachInfo()) |
| 263 | { |
| 264 | if (path && path[0]) |
| 265 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 266 | m_opaque_sp->SetWaitForLaunch (wait_for); |
| 267 | } |
| 268 | |
| 269 | SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) : |
| 270 | m_opaque_sp (new ProcessAttachInfo()) |
| 271 | { |
| 272 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 273 | } |
| 274 | |
| 275 | SBAttachInfo & |
| 276 | SBAttachInfo::operator = (const SBAttachInfo &rhs) |
| 277 | { |
| 278 | if (this != &rhs) |
| 279 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 280 | return *this; |
| 281 | } |
| 282 | |
| 283 | lldb::pid_t |
| 284 | SBAttachInfo::GetProcessID () |
| 285 | { |
| 286 | return m_opaque_sp->GetProcessID(); |
| 287 | } |
| 288 | |
| 289 | void |
| 290 | SBAttachInfo::SetProcessID (lldb::pid_t pid) |
| 291 | { |
| 292 | m_opaque_sp->SetProcessID (pid); |
| 293 | } |
| 294 | |
| 295 | |
| 296 | uint32_t |
| 297 | SBAttachInfo::GetResumeCount () |
| 298 | { |
| 299 | return m_opaque_sp->GetResumeCount(); |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | SBAttachInfo::SetResumeCount (uint32_t c) |
| 304 | { |
| 305 | m_opaque_sp->SetResumeCount (c); |
| 306 | } |
| 307 | |
| 308 | const char * |
| 309 | SBAttachInfo::GetProcessPluginName () |
| 310 | { |
| 311 | return m_opaque_sp->GetProcessPluginName(); |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | SBAttachInfo::SetProcessPluginName (const char *plugin_name) |
| 316 | { |
| 317 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 318 | } |
| 319 | |
| 320 | void |
| 321 | SBAttachInfo::SetExecutable (const char *path) |
| 322 | { |
| 323 | if (path && path[0]) |
| 324 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 325 | else |
| 326 | m_opaque_sp->GetExecutableFile().Clear(); |
| 327 | } |
| 328 | |
| 329 | void |
| 330 | SBAttachInfo::SetExecutable (SBFileSpec exe_file) |
| 331 | { |
| 332 | if (exe_file.IsValid()) |
| 333 | m_opaque_sp->GetExecutableFile() = exe_file.ref(); |
| 334 | else |
| 335 | m_opaque_sp->GetExecutableFile().Clear(); |
| 336 | } |
| 337 | |
| 338 | bool |
| 339 | SBAttachInfo::GetWaitForLaunch () |
| 340 | { |
| 341 | return m_opaque_sp->GetWaitForLaunch(); |
| 342 | } |
| 343 | |
| 344 | void |
| 345 | SBAttachInfo::SetWaitForLaunch (bool b) |
| 346 | { |
| 347 | m_opaque_sp->SetWaitForLaunch (b); |
| 348 | } |
| 349 | |
| 350 | uint32_t |
| 351 | SBAttachInfo::GetEffectiveUserID() |
| 352 | { |
| 353 | return m_opaque_sp->GetEffectiveUserID(); |
| 354 | } |
| 355 | |
| 356 | uint32_t |
| 357 | SBAttachInfo::GetEffectiveGroupID() |
| 358 | { |
| 359 | return m_opaque_sp->GetEffectiveGroupID(); |
| 360 | } |
| 361 | |
| 362 | bool |
| 363 | SBAttachInfo::EffectiveUserIDIsValid () |
| 364 | { |
| 365 | return m_opaque_sp->EffectiveUserIDIsValid(); |
| 366 | } |
| 367 | |
| 368 | bool |
| 369 | SBAttachInfo::EffectiveGroupIDIsValid () |
| 370 | { |
| 371 | return m_opaque_sp->EffectiveGroupIDIsValid (); |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | SBAttachInfo::SetEffectiveUserID (uint32_t uid) |
| 376 | { |
| 377 | m_opaque_sp->SetEffectiveUserID(uid); |
| 378 | } |
| 379 | |
| 380 | void |
| 381 | SBAttachInfo::SetEffectiveGroupID (uint32_t gid) |
| 382 | { |
| 383 | m_opaque_sp->SetEffectiveGroupID(gid); |
| 384 | } |
| 385 | |
| 386 | lldb::pid_t |
| 387 | SBAttachInfo::GetParentProcessID () |
| 388 | { |
| 389 | return m_opaque_sp->GetParentProcessID(); |
| 390 | } |
| 391 | |
| 392 | void |
| 393 | SBAttachInfo::SetParentProcessID (lldb::pid_t pid) |
| 394 | { |
| 395 | m_opaque_sp->SetParentProcessID (pid); |
| 396 | } |
| 397 | |
| 398 | bool |
| 399 | SBAttachInfo::ParentProcessIDIsValid() |
| 400 | { |
| 401 | return m_opaque_sp->ParentProcessIDIsValid(); |
| 402 | } |
| 403 | |
| 404 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | //---------------------------------------------------------------------- |
| 406 | // SBTarget constructor |
| 407 | //---------------------------------------------------------------------- |
Greg Clayton | c3b61d2 | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 408 | SBTarget::SBTarget () : |
| 409 | m_opaque_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 410 | { |
| 411 | } |
| 412 | |
| 413 | SBTarget::SBTarget (const SBTarget& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 414 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | { |
| 416 | } |
| 417 | |
| 418 | SBTarget::SBTarget(const TargetSP& target_sp) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 419 | m_opaque_sp (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | { |
| 421 | } |
| 422 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 423 | const SBTarget& |
| 424 | SBTarget::operator = (const SBTarget& rhs) |
| 425 | { |
| 426 | if (this != &rhs) |
| 427 | m_opaque_sp = rhs.m_opaque_sp; |
| 428 | return *this; |
| 429 | } |
| 430 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 431 | //---------------------------------------------------------------------- |
| 432 | // Destructor |
| 433 | //---------------------------------------------------------------------- |
| 434 | SBTarget::~SBTarget() |
| 435 | { |
| 436 | } |
| 437 | |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 438 | const char * |
| 439 | SBTarget::GetBroadcasterClassName () |
| 440 | { |
| 441 | return Target::GetStaticBroadcasterClass().AsCString(); |
| 442 | } |
| 443 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 444 | bool |
| 445 | SBTarget::IsValid () const |
| 446 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 447 | return m_opaque_sp.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | SBProcess |
| 451 | SBTarget::GetProcess () |
| 452 | { |
| 453 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 454 | ProcessSP process_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 455 | TargetSP target_sp(GetSP()); |
| 456 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 457 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 458 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 459 | sb_process.SetSP (process_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 460 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 461 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 462 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 463 | if (log) |
| 464 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 465 | log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 466 | target_sp.get(), process_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | return sb_process; |
| 470 | } |
| 471 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 472 | SBDebugger |
| 473 | SBTarget::GetDebugger () const |
| 474 | { |
| 475 | SBDebugger debugger; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 476 | TargetSP target_sp(GetSP()); |
| 477 | if (target_sp) |
| 478 | debugger.reset (target_sp->GetDebugger().shared_from_this()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 479 | return debugger; |
| 480 | } |
| 481 | |
Jim Ingham | b5871fe | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 482 | SBProcess |
| 483 | SBTarget::LaunchSimple |
| 484 | ( |
| 485 | char const **argv, |
| 486 | char const **envp, |
| 487 | const char *working_directory |
| 488 | ) |
| 489 | { |
| 490 | char *stdin_path = NULL; |
| 491 | char *stdout_path = NULL; |
| 492 | char *stderr_path = NULL; |
| 493 | uint32_t launch_flags = 0; |
| 494 | bool stop_at_entry = false; |
| 495 | SBError error; |
| 496 | SBListener listener = GetDebugger().GetListener(); |
| 497 | return Launch (listener, |
| 498 | argv, |
| 499 | envp, |
| 500 | stdin_path, |
| 501 | stdout_path, |
| 502 | stderr_path, |
| 503 | working_directory, |
| 504 | launch_flags, |
| 505 | stop_at_entry, |
| 506 | error); |
| 507 | } |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 508 | |
| 509 | SBProcess |
| 510 | SBTarget::Launch |
| 511 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 512 | SBListener &listener, |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 513 | char const **argv, |
| 514 | char const **envp, |
| 515 | const char *stdin_path, |
| 516 | const char *stdout_path, |
| 517 | const char *stderr_path, |
| 518 | const char *working_directory, |
| 519 | uint32_t launch_flags, // See LaunchFlags |
| 520 | bool stop_at_entry, |
| 521 | lldb::SBError& error |
| 522 | ) |
| 523 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 524 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 525 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 526 | SBProcess sb_process; |
| 527 | ProcessSP process_sp; |
| 528 | TargetSP target_sp(GetSP()); |
| 529 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 530 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 531 | { |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 532 | log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 533 | target_sp.get(), |
Greg Clayton | de915be | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 534 | argv, |
| 535 | envp, |
| 536 | stdin_path ? stdin_path : "NULL", |
| 537 | stdout_path ? stdout_path : "NULL", |
| 538 | stderr_path ? stderr_path : "NULL", |
| 539 | working_directory ? working_directory : "NULL", |
| 540 | launch_flags, |
| 541 | stop_at_entry, |
| 542 | error.get()); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 543 | } |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 544 | |
| 545 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 547 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 548 | |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 549 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) |
| 550 | launch_flags |= eLaunchFlagDisableASLR; |
| 551 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 552 | StateType state = eStateInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 553 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 554 | if (process_sp) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 555 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 556 | state = process_sp->GetState(); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 557 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 558 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 559 | { |
| 560 | if (state == eStateAttaching) |
| 561 | error.SetErrorString ("process attach is in progress"); |
| 562 | else |
| 563 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 564 | return sb_process; |
| 565 | } |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 568 | if (state == eStateConnected) |
| 569 | { |
| 570 | // If we are already connected, then we have already specified the |
| 571 | // listener, so if a valid listener is supplied, we need to error out |
| 572 | // to let the client know. |
| 573 | if (listener.IsValid()) |
| 574 | { |
| 575 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 576 | return sb_process; |
| 577 | } |
| 578 | } |
| 579 | else |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 580 | { |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 581 | if (listener.IsValid()) |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 582 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 583 | else |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 584 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 585 | } |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 586 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 587 | if (process_sp) |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 588 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 589 | sb_process.SetSP (process_sp); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 590 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) |
| 591 | launch_flags |= eLaunchFlagDisableSTDIO; |
| 592 | |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 593 | ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); |
| 594 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 595 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 596 | if (exe_module) |
Greg Clayton | 1d1f39e | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 597 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 598 | if (argv) |
| 599 | launch_info.GetArguments().AppendArguments (argv); |
| 600 | if (envp) |
| 601 | launch_info.GetEnvironmentEntries ().SetArguments (envp); |
| 602 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 603 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 604 | if (error.Success()) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 605 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 606 | // We we are stopping at the entry point, we can return now! |
| 607 | if (stop_at_entry) |
| 608 | return sb_process; |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 609 | |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 610 | // Make sure we are stopped at the entry |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 611 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 612 | if (state == eStateStopped) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 613 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 614 | // resume the process to skip the entry point |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 615 | error.SetError (process_sp->Resume()); |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 616 | if (error.Success()) |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 617 | { |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 618 | // If we are doing synchronous mode, then wait for the |
| 619 | // process to stop yet again! |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 620 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 621 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 7c330d6 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
Greg Clayton | 180546b | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 625 | } |
| 626 | else |
| 627 | { |
| 628 | error.SetErrorString ("unable to create lldb_private::Process"); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | error.SetErrorString ("SBTarget is invalid"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 635 | |
Caroline Tice | 926060e | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 636 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 637 | if (log) |
| 638 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 639 | log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 640 | target_sp.get(), process_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Greg Clayton | 1a3083a | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 643 | return sb_process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 646 | SBProcess |
| 647 | SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) |
| 648 | { |
| 649 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 650 | |
| 651 | SBProcess sb_process; |
| 652 | ProcessSP process_sp; |
| 653 | TargetSP target_sp(GetSP()); |
| 654 | |
| 655 | if (log) |
| 656 | { |
| 657 | log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get()); |
| 658 | } |
| 659 | |
| 660 | if (target_sp) |
| 661 | { |
| 662 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 663 | StateType state = eStateInvalid; |
| 664 | process_sp = target_sp->GetProcessSP(); |
| 665 | if (process_sp) |
| 666 | { |
| 667 | state = process_sp->GetState(); |
| 668 | |
| 669 | if (process_sp->IsAlive() && state != eStateConnected) |
| 670 | { |
| 671 | if (state == eStateAttaching) |
| 672 | error.SetErrorString ("process attach is in progress"); |
| 673 | else |
| 674 | error.SetErrorString ("a process is already being debugged"); |
| 675 | return sb_process; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | if (state != eStateConnected) |
| 680 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 681 | |
| 682 | if (process_sp) |
| 683 | { |
| 684 | sb_process.SetSP (process_sp); |
| 685 | lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref(); |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 686 | |
| 687 | bool add_exe_as_first_argv = true; //launch_info.GetArguments().GetArgumentCount() == 0; |
| 688 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 689 | if (exe_module) |
| 690 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), add_exe_as_first_argv); |
| 691 | |
| 692 | const ArchSpec &arch_spec = target_sp->GetArchitecture(); |
| 693 | if (arch_spec.IsValid()) |
| 694 | launch_info.GetArchitecture () = arch_spec; |
| 695 | |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 696 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 697 | const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false; |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 698 | if (error.Success()) |
| 699 | { |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 700 | StateType state = eStateInvalid; |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 701 | if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 702 | { |
| 703 | // If we are doing synchronous mode, then wait for the initial |
| 704 | // stop to happen, else, return and let the caller watch for |
| 705 | // the stop |
| 706 | if (synchronous_execution) |
| 707 | state = process_sp->WaitForProcessToStop (NULL); |
| 708 | // We we are stopping at the entry point, we can return now! |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 709 | return sb_process; |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 710 | } |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 711 | |
| 712 | // Make sure we are stopped at the entry |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 713 | state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 714 | if (state == eStateStopped) |
| 715 | { |
| 716 | // resume the process to skip the entry point |
| 717 | error.SetError (process_sp->Resume()); |
| 718 | if (error.Success()) |
| 719 | { |
| 720 | // If we are doing synchronous mode, then wait for the |
| 721 | // process to stop yet again! |
Greg Clayton | 98ca1e6 | 2012-02-24 20:59:25 +0000 | [diff] [blame^] | 722 | if (synchronous_execution) |
Greg Clayton | 0a8dcac | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 723 | process_sp->WaitForProcessToStop (NULL); |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 731 | } |
| 732 | } |
| 733 | else |
| 734 | { |
| 735 | error.SetErrorString ("SBTarget is invalid"); |
| 736 | } |
| 737 | |
| 738 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 739 | if (log) |
| 740 | { |
| 741 | log->Printf ("SBTarget(%p)::Launch (...) => SBProceess(%p)", |
| 742 | target_sp.get(), process_sp.get()); |
| 743 | } |
| 744 | |
| 745 | return sb_process; |
| 746 | } |
| 747 | |
| 748 | lldb::SBProcess |
| 749 | SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error) |
| 750 | { |
| 751 | SBProcess sb_process; |
| 752 | ProcessSP process_sp; |
| 753 | TargetSP target_sp(GetSP()); |
| 754 | if (target_sp) |
| 755 | { |
| 756 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 757 | |
| 758 | StateType state = eStateInvalid; |
| 759 | process_sp = target_sp->GetProcessSP(); |
| 760 | if (process_sp) |
| 761 | { |
| 762 | state = process_sp->GetState(); |
| 763 | |
| 764 | if (process_sp->IsAlive() && state != eStateConnected) |
| 765 | { |
| 766 | if (state == eStateAttaching) |
| 767 | error.SetErrorString ("process attach is in progress"); |
| 768 | else |
| 769 | error.SetErrorString ("a process is already being debugged"); |
| 770 | return sb_process; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | if (state != eStateConnected) |
| 775 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 776 | |
| 777 | if (process_sp) |
| 778 | { |
| 779 | sb_process.SetSP (process_sp); |
| 780 | |
| 781 | ProcessAttachInfo &attach_info = sb_attach_info.ref(); |
| 782 | error.SetError (process_sp->Attach (attach_info)); |
| 783 | // If we are doing synchronous mode, then wait for the |
| 784 | // process to stop! |
| 785 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
| 786 | process_sp->WaitForProcessToStop (NULL); |
| 787 | } |
| 788 | else |
| 789 | { |
| 790 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 791 | } |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | error.SetErrorString ("SBTarget is invalid"); |
| 796 | } |
| 797 | return sb_process; |
| 798 | } |
| 799 | |
| 800 | |
Greg Clayton | d5b0b44 | 2011-12-02 02:10:57 +0000 | [diff] [blame] | 801 | #if defined(__APPLE__) |
| 802 | |
| 803 | lldb::SBProcess |
| 804 | SBTarget::AttachToProcessWithID (SBListener &listener, |
| 805 | ::pid_t pid, |
| 806 | lldb::SBError& error) |
| 807 | { |
| 808 | return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); |
| 809 | } |
| 810 | |
| 811 | #endif // #if defined(__APPLE__) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 812 | |
| 813 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 814 | SBTarget::AttachToProcessWithID |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 815 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 816 | SBListener &listener, |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 817 | lldb::pid_t pid,// The process ID to attach to |
| 818 | SBError& error // An error explaining what went wrong if attach fails |
| 819 | ) |
| 820 | { |
| 821 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 822 | ProcessSP process_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 823 | TargetSP target_sp(GetSP()); |
| 824 | if (target_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 825 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 826 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 827 | |
| 828 | StateType state = eStateInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 829 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 830 | if (process_sp) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 831 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 832 | state = process_sp->GetState(); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 833 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 834 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 835 | { |
| 836 | if (state == eStateAttaching) |
| 837 | error.SetErrorString ("process attach is in progress"); |
| 838 | else |
| 839 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 840 | return sb_process; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (state == eStateConnected) |
| 845 | { |
| 846 | // If we are already connected, then we have already specified the |
| 847 | // listener, so if a valid listener is supplied, we need to error out |
| 848 | // to let the client know. |
| 849 | if (listener.IsValid()) |
| 850 | { |
| 851 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 852 | return sb_process; |
| 853 | } |
| 854 | } |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 855 | else |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 856 | { |
| 857 | if (listener.IsValid()) |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 858 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 859 | else |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 860 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 861 | } |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 862 | if (process_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 863 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 864 | sb_process.SetSP (process_sp); |
| 865 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 866 | ProcessAttachInfo attach_info; |
| 867 | attach_info.SetProcessID (pid); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 868 | error.SetError (process_sp->Attach (attach_info)); |
Johnny Chen | 535960e | 2011-06-17 00:51:15 +0000 | [diff] [blame] | 869 | // If we are doing synchronous mode, then wait for the |
| 870 | // process to stop! |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 871 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 872 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 873 | } |
| 874 | else |
| 875 | { |
| 876 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 877 | } |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | error.SetErrorString ("SBTarget is invalid"); |
| 882 | } |
| 883 | return sb_process; |
| 884 | |
| 885 | } |
| 886 | |
| 887 | lldb::SBProcess |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 888 | SBTarget::AttachToProcessWithName |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 889 | ( |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 890 | SBListener &listener, |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 891 | const char *name, // basename of process to attach to |
| 892 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 893 | SBError& error // An error explaining what went wrong if attach fails |
| 894 | ) |
| 895 | { |
| 896 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 897 | ProcessSP process_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 898 | TargetSP target_sp(GetSP()); |
| 899 | if (name && target_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 900 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 901 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 902 | |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 903 | StateType state = eStateInvalid; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 904 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 905 | if (process_sp) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 906 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 907 | state = process_sp->GetState(); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 908 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 909 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 910 | { |
| 911 | if (state == eStateAttaching) |
| 912 | error.SetErrorString ("process attach is in progress"); |
| 913 | else |
| 914 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 915 | return sb_process; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (state == eStateConnected) |
| 920 | { |
| 921 | // If we are already connected, then we have already specified the |
| 922 | // listener, so if a valid listener is supplied, we need to error out |
| 923 | // to let the client know. |
| 924 | if (listener.IsValid()) |
| 925 | { |
| 926 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 927 | return sb_process; |
| 928 | } |
| 929 | } |
Greg Clayton | 271a5db | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 930 | else |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 931 | { |
| 932 | if (listener.IsValid()) |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 933 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 934 | else |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 935 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | de1dd81 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 936 | } |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 937 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 938 | if (process_sp) |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 939 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 940 | sb_process.SetSP (process_sp); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 941 | ProcessAttachInfo attach_info; |
| 942 | attach_info.GetExecutableFile().SetFile(name, false); |
| 943 | attach_info.SetWaitForLaunch(wait_for); |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 944 | error.SetError (process_sp->Attach (attach_info)); |
Johnny Chen | 58d02ff | 2011-06-17 19:21:30 +0000 | [diff] [blame] | 945 | // If we are doing synchronous mode, then wait for the |
| 946 | // process to stop! |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 947 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 948 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | c5f728c | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 949 | } |
| 950 | else |
| 951 | { |
| 952 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 953 | } |
| 954 | } |
| 955 | else |
| 956 | { |
| 957 | error.SetErrorString ("SBTarget is invalid"); |
| 958 | } |
| 959 | return sb_process; |
| 960 | |
| 961 | } |
| 962 | |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 963 | lldb::SBProcess |
| 964 | SBTarget::ConnectRemote |
| 965 | ( |
| 966 | SBListener &listener, |
| 967 | const char *url, |
| 968 | const char *plugin_name, |
| 969 | SBError& error |
| 970 | ) |
| 971 | { |
| 972 | SBProcess sb_process; |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 973 | ProcessSP process_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 974 | TargetSP target_sp(GetSP()); |
| 975 | if (target_sp) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 976 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 977 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 978 | if (listener.IsValid()) |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 979 | process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 980 | else |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 981 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 982 | |
| 983 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 984 | if (process_sp) |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 985 | { |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 986 | sb_process.SetSP (process_sp); |
| 987 | error.SetError (process_sp->ConnectRemote (url)); |
James McIlree | 3809340 | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 988 | } |
| 989 | else |
| 990 | { |
| 991 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 992 | } |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | error.SetErrorString ("SBTarget is invalid"); |
| 997 | } |
| 998 | return sb_process; |
| 999 | } |
| 1000 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | SBFileSpec |
| 1002 | SBTarget::GetExecutable () |
| 1003 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1004 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1005 | SBFileSpec exe_file_spec; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1006 | TargetSP target_sp(GetSP()); |
| 1007 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1008 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1009 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1010 | if (exe_module) |
| 1011 | exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1012 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1013 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1014 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1015 | if (log) |
| 1016 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1017 | log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1018 | target_sp.get(), exe_file_spec.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1021 | return exe_file_spec; |
| 1022 | } |
| 1023 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1024 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1025 | SBTarget::operator == (const SBTarget &rhs) const |
| 1026 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1027 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | bool |
| 1031 | SBTarget::operator != (const SBTarget &rhs) const |
| 1032 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1033 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1036 | lldb::TargetSP |
| 1037 | SBTarget::GetSP () const |
Greg Clayton | 15afa9f | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 1038 | { |
| 1039 | return m_opaque_sp; |
| 1040 | } |
| 1041 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1042 | void |
Greg Clayton | 334d33a | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1043 | SBTarget::SetSP (const lldb::TargetSP& target_sp) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1044 | { |
| 1045 | m_opaque_sp = target_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1048 | lldb::SBAddress |
| 1049 | SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1050 | { |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1051 | lldb::SBAddress sb_addr; |
| 1052 | Address &addr = sb_addr.ref(); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1053 | TargetSP target_sp(GetSP()); |
| 1054 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1055 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1056 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1057 | if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1058 | return sb_addr; |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1059 | } |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1060 | |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1061 | // We have a load address that isn't in a section, just return an address |
| 1062 | // with the offset filled in (the address) and the section set to NULL |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1063 | addr.SetRawAddress(vm_addr); |
Greg Clayton | a395506 | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1064 | return sb_addr; |
Greg Clayton | ea49cc7 | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Greg Clayton | afb8186 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1067 | SBSymbolContext |
| 1068 | SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope) |
| 1069 | { |
| 1070 | SBSymbolContext sc; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1071 | if (addr.IsValid()) |
| 1072 | { |
| 1073 | TargetSP target_sp(GetSP()); |
| 1074 | if (target_sp) |
| 1075 | target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); |
| 1076 | } |
Greg Clayton | afb8186 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1077 | return sc; |
| 1078 | } |
| 1079 | |
| 1080 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | SBBreakpoint |
| 1082 | SBTarget::BreakpointCreateByLocation (const char *file, uint32_t line) |
| 1083 | { |
Greg Clayton | d6d806c | 2010-11-08 00:28:40 +0000 | [diff] [blame] | 1084 | return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | SBBreakpoint |
| 1088 | SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t line) |
| 1089 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1090 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1091 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1093 | TargetSP target_sp(GetSP()); |
| 1094 | if (target_sp && line != 0) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1095 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1096 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1097 | *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1098 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1099 | |
| 1100 | if (log) |
| 1101 | { |
| 1102 | SBStream sstr; |
| 1103 | sb_bp.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1104 | char path[PATH_MAX]; |
| 1105 | sb_file_spec->GetPath (path, sizeof(path)); |
| 1106 | log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1107 | target_sp.get(), |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1108 | path, |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1109 | line, |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1110 | sb_bp.get(), |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1111 | sstr.GetData()); |
| 1112 | } |
| 1113 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | return sb_bp; |
| 1115 | } |
| 1116 | |
| 1117 | SBBreakpoint |
| 1118 | SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_name) |
| 1119 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1120 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1121 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1123 | TargetSP target_sp(GetSP()); |
| 1124 | if (target_sp.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1125 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1126 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | if (module_name && module_name[0]) |
| 1128 | { |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1129 | FileSpecList module_spec_list; |
| 1130 | module_spec_list.Append (FileSpec (module_name, false)); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1131 | *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1132 | } |
| 1133 | else |
| 1134 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1135 | *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1136 | } |
| 1137 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1138 | |
| 1139 | if (log) |
| 1140 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1141 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1142 | target_sp.get(), symbol_name, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1145 | return sb_bp; |
| 1146 | } |
| 1147 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1148 | lldb::SBBreakpoint |
| 1149 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 1150 | const SBFileSpecList &module_list, |
| 1151 | const SBFileSpecList &comp_unit_list) |
| 1152 | { |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1153 | uint32_t name_type_mask = eFunctionNameTypeAuto; |
| 1154 | return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); |
| 1155 | } |
| 1156 | |
| 1157 | lldb::SBBreakpoint |
| 1158 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 1159 | uint32_t name_type_mask, |
| 1160 | const SBFileSpecList &module_list, |
| 1161 | const SBFileSpecList &comp_unit_list) |
| 1162 | { |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1163 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1164 | |
| 1165 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1166 | TargetSP target_sp(GetSP()); |
| 1167 | if (target_sp && symbol_name && symbol_name[0]) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1168 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1169 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1170 | *sb_bp = target_sp->CreateBreakpoint (module_list.get(), |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1171 | comp_unit_list.get(), |
| 1172 | symbol_name, |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1173 | name_type_mask, |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1174 | false); |
| 1175 | } |
| 1176 | |
| 1177 | if (log) |
| 1178 | { |
Jim Ingham | 1fb8a2d | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1179 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1180 | target_sp.get(), symbol_name, name_type_mask, sb_bp.get()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | return sb_bp; |
| 1184 | } |
| 1185 | |
| 1186 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | SBBreakpoint |
| 1188 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *module_name) |
| 1189 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1190 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1191 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1192 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1193 | TargetSP target_sp(GetSP()); |
| 1194 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1195 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1196 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | RegularExpression regexp(symbol_name_regex); |
| 1198 | |
| 1199 | if (module_name && module_name[0]) |
| 1200 | { |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1201 | FileSpecList module_spec_list; |
| 1202 | module_spec_list.Append (FileSpec (module_name, false)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1204 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1205 | } |
| 1206 | else |
| 1207 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1208 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1209 | } |
| 1210 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1211 | |
| 1212 | if (log) |
| 1213 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1214 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1215 | target_sp.get(), symbol_name_regex, module_name, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | return sb_bp; |
| 1219 | } |
| 1220 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1221 | lldb::SBBreakpoint |
| 1222 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, |
| 1223 | const SBFileSpecList &module_list, |
| 1224 | const SBFileSpecList &comp_unit_list) |
| 1225 | { |
| 1226 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1227 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1228 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1229 | TargetSP target_sp(GetSP()); |
| 1230 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1231 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1232 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1233 | RegularExpression regexp(symbol_name_regex); |
| 1234 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1235 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, false); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | if (log) |
| 1239 | { |
| 1240 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1241 | target_sp.get(), symbol_name_regex, sb_bp.get()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | return sb_bp; |
| 1245 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1246 | |
| 1247 | SBBreakpoint |
| 1248 | SBTarget::BreakpointCreateByAddress (addr_t address) |
| 1249 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1250 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1251 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1252 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1253 | TargetSP target_sp(GetSP()); |
| 1254 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1255 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1256 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1257 | *sb_bp = target_sp->CreateBreakpoint (address, false); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1258 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1259 | |
| 1260 | if (log) |
| 1261 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1262 | log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%llu) => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1265 | return sb_bp; |
| 1266 | } |
| 1267 | |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1268 | lldb::SBBreakpoint |
| 1269 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, const lldb::SBFileSpec &source_file, const char *module_name) |
| 1270 | { |
| 1271 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1272 | |
| 1273 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1274 | TargetSP target_sp(GetSP()); |
| 1275 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1276 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1277 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1278 | RegularExpression regexp(source_regex); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1279 | FileSpecList source_file_spec_list; |
| 1280 | source_file_spec_list.Append (source_file.ref()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1281 | |
| 1282 | if (module_name && module_name[0]) |
| 1283 | { |
| 1284 | FileSpecList module_spec_list; |
| 1285 | module_spec_list.Append (FileSpec (module_name, false)); |
| 1286 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1287 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1288 | } |
| 1289 | else |
| 1290 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1291 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if (log) |
| 1296 | { |
| 1297 | char path[PATH_MAX]; |
| 1298 | source_file->GetPath (path, sizeof(path)); |
| 1299 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1300 | target_sp.get(), source_regex, path, module_name, sb_bp.get()); |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | return sb_bp; |
| 1304 | } |
| 1305 | |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1306 | lldb::SBBreakpoint |
| 1307 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, |
| 1308 | const SBFileSpecList &module_list, |
| 1309 | const lldb::SBFileSpecList &source_file_list) |
| 1310 | { |
| 1311 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1312 | |
| 1313 | SBBreakpoint sb_bp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1314 | TargetSP target_sp(GetSP()); |
| 1315 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1316 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1317 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1318 | RegularExpression regexp(source_regex); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1319 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | if (log) |
| 1323 | { |
| 1324 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1325 | target_sp.get(), source_regex, sb_bp.get()); |
Jim Ingham | d6d4797 | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | return sb_bp; |
| 1329 | } |
Jim Ingham | 03c8ee5 | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1330 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1331 | uint32_t |
| 1332 | SBTarget::GetNumBreakpoints () const |
| 1333 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1334 | TargetSP target_sp(GetSP()); |
| 1335 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1336 | { |
| 1337 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1338 | return target_sp->GetBreakpointList().GetSize(); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1339 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | SBBreakpoint |
| 1344 | SBTarget::GetBreakpointAtIndex (uint32_t idx) const |
| 1345 | { |
| 1346 | SBBreakpoint sb_breakpoint; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1347 | TargetSP target_sp(GetSP()); |
| 1348 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1349 | { |
| 1350 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1351 | *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1352 | } |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1353 | return sb_breakpoint; |
| 1354 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | |
| 1356 | bool |
| 1357 | SBTarget::BreakpointDelete (break_id_t bp_id) |
| 1358 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1359 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1360 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1361 | bool result = false; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1362 | TargetSP target_sp(GetSP()); |
| 1363 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1364 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1365 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1366 | result = target_sp->RemoveBreakpointByID (bp_id); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1367 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1368 | |
| 1369 | if (log) |
| 1370 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1371 | log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1377 | SBBreakpoint |
| 1378 | SBTarget::FindBreakpointByID (break_id_t bp_id) |
| 1379 | { |
| 1380 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1381 | |
| 1382 | SBBreakpoint sb_breakpoint; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1383 | TargetSP target_sp(GetSP()); |
| 1384 | if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1385 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1386 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1387 | *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | if (log) |
| 1391 | { |
| 1392 | log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1393 | target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | return sb_breakpoint; |
| 1397 | } |
| 1398 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1399 | bool |
| 1400 | SBTarget::EnableAllBreakpoints () |
| 1401 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1402 | TargetSP target_sp(GetSP()); |
| 1403 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1404 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1405 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1406 | target_sp->EnableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1407 | return true; |
| 1408 | } |
| 1409 | return false; |
| 1410 | } |
| 1411 | |
| 1412 | bool |
| 1413 | SBTarget::DisableAllBreakpoints () |
| 1414 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1415 | TargetSP target_sp(GetSP()); |
| 1416 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1417 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1418 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1419 | target_sp->DisableAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1420 | return true; |
| 1421 | } |
| 1422 | return false; |
| 1423 | } |
| 1424 | |
| 1425 | bool |
| 1426 | SBTarget::DeleteAllBreakpoints () |
| 1427 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1428 | TargetSP target_sp(GetSP()); |
| 1429 | if (target_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1430 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1431 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1432 | target_sp->RemoveAllBreakpoints (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1433 | return true; |
| 1434 | } |
| 1435 | return false; |
| 1436 | } |
| 1437 | |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1438 | uint32_t |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1439 | SBTarget::GetNumWatchpoints () const |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1440 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1441 | TargetSP target_sp(GetSP()); |
| 1442 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1443 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1444 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1445 | return target_sp->GetWatchpointList().GetSize(); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1446 | } |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1450 | SBWatchpoint |
| 1451 | SBTarget::GetWatchpointAtIndex (uint32_t idx) const |
Johnny Chen | 5eb54bb | 2011-09-27 20:29:45 +0000 | [diff] [blame] | 1452 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1453 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1454 | TargetSP target_sp(GetSP()); |
| 1455 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1456 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1457 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1458 | sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1459 | } |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1460 | return sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1464 | SBTarget::DeleteWatchpoint (watch_id_t wp_id) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1465 | { |
| 1466 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1467 | |
| 1468 | bool result = false; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1469 | TargetSP target_sp(GetSP()); |
| 1470 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1471 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1472 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1473 | result = target_sp->RemoveWatchpointByID (wp_id); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | if (log) |
| 1477 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1478 | log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | return result; |
| 1482 | } |
| 1483 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1484 | SBWatchpoint |
| 1485 | SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1486 | { |
| 1487 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1488 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1489 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1490 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1491 | TargetSP target_sp(GetSP()); |
| 1492 | if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1493 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1494 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1495 | watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); |
| 1496 | sb_watchpoint.SetSP (watchpoint_sp); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | if (log) |
| 1500 | { |
Johnny Chen | ecd4feb | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1501 | log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1502 | target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get()); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1505 | return sb_watchpoint; |
| 1506 | } |
| 1507 | |
| 1508 | lldb::SBWatchpoint |
| 1509 | SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write) |
| 1510 | { |
| 1511 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1512 | |
| 1513 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1514 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1515 | TargetSP target_sp(GetSP()); |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1516 | if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1517 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1518 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1519 | uint32_t watch_type = 0; |
| 1520 | if (read) |
| 1521 | watch_type |= LLDB_WATCH_TYPE_READ; |
| 1522 | if (write) |
| 1523 | watch_type |= LLDB_WATCH_TYPE_WRITE; |
| 1524 | watchpoint_sp = target_sp->CreateWatchpoint(addr, size, watch_type); |
| 1525 | sb_watchpoint.SetSP (watchpoint_sp); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | if (log) |
| 1529 | { |
| 1530 | log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%llx, 0x%u) => SBWatchpoint(%p)", |
Greg Clayton | 0a19a1b | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1531 | target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get()); |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | return sb_watchpoint; |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1538 | SBTarget::EnableAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1539 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1540 | TargetSP target_sp(GetSP()); |
| 1541 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1542 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1543 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1544 | target_sp->EnableAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1545 | return true; |
| 1546 | } |
| 1547 | return false; |
| 1548 | } |
| 1549 | |
| 1550 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1551 | SBTarget::DisableAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1552 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1553 | TargetSP target_sp(GetSP()); |
| 1554 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1555 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1556 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1557 | target_sp->DisableAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1558 | return true; |
| 1559 | } |
| 1560 | return false; |
| 1561 | } |
| 1562 | |
| 1563 | bool |
Greg Clayton | 1fa6b3d | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1564 | SBTarget::DeleteAllWatchpoints () |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1565 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1566 | TargetSP target_sp(GetSP()); |
| 1567 | if (target_sp) |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1568 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1569 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1570 | target_sp->RemoveAllWatchpoints (); |
Johnny Chen | 096c293 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1571 | return true; |
| 1572 | } |
| 1573 | return false; |
| 1574 | } |
| 1575 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1576 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1577 | lldb::SBModule |
| 1578 | SBTarget::AddModule (const char *path, |
| 1579 | const char *triple, |
| 1580 | const char *uuid_cstr) |
| 1581 | { |
| 1582 | lldb::SBModule sb_module; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1583 | TargetSP target_sp(GetSP()); |
| 1584 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1585 | { |
| 1586 | FileSpec module_file_spec; |
| 1587 | UUID module_uuid; |
| 1588 | ArchSpec module_arch; |
| 1589 | |
| 1590 | if (path) |
| 1591 | module_file_spec.SetFile(path, false); |
| 1592 | |
| 1593 | if (uuid_cstr) |
| 1594 | module_uuid.SetfromCString(uuid_cstr); |
| 1595 | |
| 1596 | if (triple) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1597 | module_arch.SetTriple (triple, target_sp->GetPlatform ().get()); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1598 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1599 | sb_module.SetSP(target_sp->GetSharedModule (module_file_spec, |
| 1600 | module_arch, |
| 1601 | uuid_cstr ? &module_uuid : NULL)); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1602 | } |
| 1603 | return sb_module; |
| 1604 | } |
| 1605 | |
| 1606 | bool |
| 1607 | SBTarget::AddModule (lldb::SBModule &module) |
| 1608 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1609 | TargetSP target_sp(GetSP()); |
| 1610 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1611 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1612 | target_sp->GetImages().AppendIfNeeded (module.GetSP()); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1613 | return true; |
| 1614 | } |
| 1615 | return false; |
| 1616 | } |
| 1617 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1618 | uint32_t |
| 1619 | SBTarget::GetNumModules () const |
| 1620 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1621 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1622 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1623 | uint32_t num = 0; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1624 | TargetSP target_sp(GetSP()); |
| 1625 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1626 | { |
| 1627 | // The module list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1628 | num = target_sp->GetImages().GetSize(); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1629 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1630 | |
| 1631 | if (log) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1632 | log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1633 | |
| 1634 | return num; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1637 | void |
| 1638 | SBTarget::Clear () |
| 1639 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1640 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1641 | |
| 1642 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1643 | log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1644 | |
Greg Clayton | 43490d1 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 1645 | m_opaque_sp.reset(); |
| 1646 | } |
| 1647 | |
| 1648 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1649 | SBModule |
| 1650 | SBTarget::FindModule (const SBFileSpec &sb_file_spec) |
| 1651 | { |
| 1652 | SBModule sb_module; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1653 | TargetSP target_sp(GetSP()); |
| 1654 | if (target_sp && sb_file_spec.IsValid()) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1655 | { |
| 1656 | // The module list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1657 | sb_module.SetSP (target_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL, NULL)); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1658 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1659 | return sb_module; |
| 1660 | } |
| 1661 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1662 | lldb::ByteOrder |
| 1663 | SBTarget::GetByteOrder () |
| 1664 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1665 | TargetSP target_sp(GetSP()); |
| 1666 | if (target_sp) |
| 1667 | return target_sp->GetArchitecture().GetByteOrder(); |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1668 | return eByteOrderInvalid; |
| 1669 | } |
| 1670 | |
| 1671 | const char * |
| 1672 | SBTarget::GetTriple () |
| 1673 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1674 | TargetSP target_sp(GetSP()); |
| 1675 | if (target_sp) |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1676 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1677 | std::string triple (target_sp->GetArchitecture().GetTriple().str()); |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1678 | // Unique the string so we don't run into ownership issues since |
| 1679 | // the const strings put the string into the string pool once and |
| 1680 | // the strings never comes out |
| 1681 | ConstString const_triple (triple.c_str()); |
| 1682 | return const_triple.GetCString(); |
| 1683 | } |
| 1684 | return NULL; |
| 1685 | } |
| 1686 | |
| 1687 | uint32_t |
| 1688 | SBTarget::GetAddressByteSize() |
| 1689 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1690 | TargetSP target_sp(GetSP()); |
| 1691 | if (target_sp) |
| 1692 | return target_sp->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 1693 | return sizeof(void*); |
| 1694 | } |
| 1695 | |
| 1696 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1697 | SBModule |
| 1698 | SBTarget::GetModuleAtIndex (uint32_t idx) |
| 1699 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1700 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1701 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1702 | SBModule sb_module; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1703 | ModuleSP module_sp; |
| 1704 | TargetSP target_sp(GetSP()); |
| 1705 | if (target_sp) |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1706 | { |
| 1707 | // The module list is thread safe, no need to lock |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1708 | module_sp = target_sp->GetImages().GetModuleAtIndex(idx); |
| 1709 | sb_module.SetSP (module_sp); |
Greg Clayton | bdcda46 | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1710 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1711 | |
| 1712 | if (log) |
| 1713 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1714 | log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1715 | target_sp.get(), idx, module_sp.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1718 | return sb_module; |
| 1719 | } |
| 1720 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1721 | bool |
| 1722 | SBTarget::RemoveModule (lldb::SBModule module) |
| 1723 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1724 | TargetSP target_sp(GetSP()); |
| 1725 | if (target_sp) |
| 1726 | return target_sp->GetImages().Remove(module.GetSP()); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1727 | return false; |
| 1728 | } |
| 1729 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1730 | |
| 1731 | SBBroadcaster |
| 1732 | SBTarget::GetBroadcaster () const |
| 1733 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1734 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1735 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1736 | TargetSP target_sp(GetSP()); |
| 1737 | SBBroadcaster broadcaster(target_sp.get(), false); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1738 | |
| 1739 | if (log) |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 1740 | log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1741 | target_sp.get(), broadcaster.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1742 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1743 | return broadcaster; |
| 1744 | } |
| 1745 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1746 | bool |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1747 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1748 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1749 | Stream &strm = description.ref(); |
| 1750 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1751 | TargetSP target_sp(GetSP()); |
| 1752 | if (target_sp) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 1753 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1754 | target_sp->Dump (&strm, description_level); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1755 | } |
| 1756 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1757 | strm.PutCString ("No value"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1758 | |
| 1759 | return true; |
| 1760 | } |
| 1761 | |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 1762 | lldb::SBSymbolContextList |
| 1763 | SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1764 | { |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 1765 | lldb::SBSymbolContextList sb_sc_list; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1766 | if (name && name[0]) |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1767 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1768 | TargetSP target_sp(GetSP()); |
| 1769 | if (target_sp) |
| 1770 | { |
| 1771 | const bool symbols_ok = true; |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1772 | const bool inlines_ok = true; |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 1773 | const bool append = true; |
| 1774 | target_sp->GetImages().FindFunctions (ConstString(name), |
| 1775 | name_type_mask, |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1776 | symbols_ok, |
| 1777 | inlines_ok, |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 1778 | append, |
| 1779 | *sb_sc_list); |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1780 | } |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1781 | } |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 1782 | return sb_sc_list; |
Greg Clayton | 4ed315f | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1785 | lldb::SBType |
| 1786 | SBTarget::FindFirstType (const char* type) |
| 1787 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1788 | TargetSP target_sp(GetSP()); |
| 1789 | if (type && target_sp) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1790 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1791 | size_t count = target_sp->GetImages().GetSize(); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1792 | for (size_t idx = 0; idx < count; idx++) |
| 1793 | { |
| 1794 | SBType found_at_idx = GetModuleAtIndex(idx).FindFirstType(type); |
| 1795 | |
| 1796 | if (found_at_idx.IsValid()) |
| 1797 | return found_at_idx; |
| 1798 | } |
| 1799 | } |
| 1800 | return SBType(); |
| 1801 | } |
| 1802 | |
| 1803 | lldb::SBTypeList |
| 1804 | SBTarget::FindTypes (const char* type) |
| 1805 | { |
| 1806 | |
| 1807 | SBTypeList retval; |
| 1808 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1809 | TargetSP target_sp(GetSP()); |
| 1810 | if (type && target_sp) |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1811 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1812 | ModuleList& images = target_sp->GetImages(); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1813 | ConstString name_const(type); |
| 1814 | SymbolContext sc; |
| 1815 | TypeList type_list; |
| 1816 | |
| 1817 | uint32_t num_matches = images.FindTypes(sc, |
| 1818 | name_const, |
| 1819 | true, |
| 1820 | UINT32_MAX, |
| 1821 | type_list); |
| 1822 | |
| 1823 | for (size_t idx = 0; idx < num_matches; idx++) |
| 1824 | { |
Greg Clayton | 0fb0bcc | 2011-08-03 22:57:10 +0000 | [diff] [blame] | 1825 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 1826 | if (type_sp) |
| 1827 | retval.Append(SBType(type_sp)); |
Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1828 | } |
| 1829 | } |
| 1830 | return retval; |
| 1831 | } |
| 1832 | |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1833 | SBValueList |
| 1834 | SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) |
| 1835 | { |
| 1836 | SBValueList sb_value_list; |
| 1837 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1838 | TargetSP target_sp(GetSP()); |
| 1839 | if (name && target_sp) |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1840 | { |
| 1841 | VariableList variable_list; |
| 1842 | const bool append = true; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1843 | const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), |
| 1844 | append, |
| 1845 | max_matches, |
| 1846 | variable_list); |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1847 | |
| 1848 | if (match_count > 0) |
| 1849 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1850 | ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1851 | if (exe_scope == NULL) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1852 | exe_scope = target_sp.get(); |
Greg Clayton | 917c000 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 1853 | ValueObjectList &value_object_list = sb_value_list.ref(); |
| 1854 | for (uint32_t i=0; i<match_count; ++i) |
| 1855 | { |
| 1856 | lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); |
| 1857 | if (valobj_sp) |
| 1858 | value_object_list.Append(valobj_sp); |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | return sb_value_list; |
| 1864 | } |
| 1865 | |
Jim Ingham | cc63746 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 1866 | SBSourceManager |
| 1867 | SBTarget::GetSourceManager() |
| 1868 | { |
| 1869 | SBSourceManager source_manager (*this); |
| 1870 | return source_manager; |
| 1871 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1872 | |
Sean Callanan | ef1f690 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 1873 | lldb::SBInstructionList |
| 1874 | SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) |
| 1875 | { |
| 1876 | SBInstructionList sb_instructions; |
| 1877 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1878 | TargetSP target_sp(GetSP()); |
| 1879 | if (target_sp) |
Sean Callanan | ef1f690 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 1880 | { |
| 1881 | Address addr; |
| 1882 | |
| 1883 | if (base_addr.get()) |
| 1884 | addr = *base_addr.get(); |
| 1885 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1886 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), |
Sean Callanan | ef1f690 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 1887 | NULL, |
| 1888 | addr, |
| 1889 | buf, |
| 1890 | size)); |
| 1891 | } |
| 1892 | |
| 1893 | return sb_instructions; |
| 1894 | } |
| 1895 | |
| 1896 | lldb::SBInstructionList |
| 1897 | SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) |
| 1898 | { |
| 1899 | return GetInstructions (ResolveLoadAddress(base_addr), buf, size); |
| 1900 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1901 | |
| 1902 | SBError |
| 1903 | SBTarget::SetSectionLoadAddress (lldb::SBSection section, |
| 1904 | lldb::addr_t section_base_addr) |
| 1905 | { |
| 1906 | SBError sb_error; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1907 | TargetSP target_sp(GetSP()); |
| 1908 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1909 | { |
| 1910 | if (!section.IsValid()) |
| 1911 | { |
| 1912 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 1913 | } |
| 1914 | else |
| 1915 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1916 | target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1922 | } |
| 1923 | return sb_error; |
| 1924 | } |
| 1925 | |
| 1926 | SBError |
| 1927 | SBTarget::ClearSectionLoadAddress (lldb::SBSection section) |
| 1928 | { |
| 1929 | SBError sb_error; |
| 1930 | |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1931 | TargetSP target_sp(GetSP()); |
| 1932 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1933 | { |
| 1934 | if (!section.IsValid()) |
| 1935 | { |
| 1936 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 1937 | } |
| 1938 | else |
| 1939 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1940 | target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP().get()); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1941 | } |
| 1942 | } |
| 1943 | else |
| 1944 | { |
| 1945 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1946 | } |
| 1947 | return sb_error; |
| 1948 | } |
| 1949 | |
| 1950 | SBError |
| 1951 | SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) |
| 1952 | { |
| 1953 | SBError sb_error; |
| 1954 | |
| 1955 | char path[PATH_MAX]; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1956 | TargetSP target_sp(GetSP()); |
| 1957 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1958 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1959 | ModuleSP module_sp (module.GetSP()); |
| 1960 | if (module_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1961 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1962 | ObjectFile *objfile = module_sp->GetObjectFile(); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1963 | if (objfile) |
| 1964 | { |
| 1965 | SectionList *section_list = objfile->GetSectionList(); |
| 1966 | if (section_list) |
| 1967 | { |
| 1968 | const size_t num_sections = section_list->GetSize(); |
| 1969 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 1970 | { |
| 1971 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 1972 | if (section_sp) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1973 | target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | else |
| 1977 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1978 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1979 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 1980 | } |
| 1981 | } |
| 1982 | else |
| 1983 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1984 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1985 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 1986 | } |
| 1987 | } |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1988 | else |
| 1989 | { |
| 1990 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 1991 | } |
| 1992 | |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 1997 | } |
| 1998 | return sb_error; |
| 1999 | } |
| 2000 | |
| 2001 | SBError |
| 2002 | SBTarget::ClearModuleLoadAddress (lldb::SBModule module) |
| 2003 | { |
| 2004 | SBError sb_error; |
| 2005 | |
| 2006 | char path[PATH_MAX]; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2007 | TargetSP target_sp(GetSP()); |
| 2008 | if (target_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2009 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2010 | ModuleSP module_sp (module.GetSP()); |
| 2011 | if (module_sp) |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2012 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2013 | ObjectFile *objfile = module_sp->GetObjectFile(); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2014 | if (objfile) |
| 2015 | { |
| 2016 | SectionList *section_list = objfile->GetSectionList(); |
| 2017 | if (section_list) |
| 2018 | { |
| 2019 | const size_t num_sections = section_list->GetSize(); |
| 2020 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 2021 | { |
| 2022 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 2023 | if (section_sp) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2024 | target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp.get()); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | else |
| 2028 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2029 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2030 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 2031 | } |
| 2032 | } |
| 2033 | else |
| 2034 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2035 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2036 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 2037 | } |
| 2038 | } |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2039 | else |
| 2040 | { |
| 2041 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 2042 | } |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2043 | } |
| 2044 | else |
| 2045 | { |
| 2046 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2047 | } |
| 2048 | return sb_error; |
| 2049 | } |
| 2050 | |
| 2051 | |