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