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