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