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