Chris Lattner | 30fdc8d | 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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBTarget.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 14 | #include "lldb/lldb-public.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBDebugger.h" |
| 17 | #include "lldb/API/SBBreakpoint.h" |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBExpressionOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBListener.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBModule.h" |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBModuleSpec.h" |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 23 | #include "lldb/API/SBSourceManager.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 24 | #include "lldb/API/SBProcess.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 25 | #include "lldb/API/SBStream.h" |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 26 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Breakpoint/BreakpointID.h" |
| 28 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 29 | #include "lldb/Breakpoint/BreakpointList.h" |
| 30 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 31 | #include "lldb/Core/Address.h" |
| 32 | #include "lldb/Core/AddressResolver.h" |
| 33 | #include "lldb/Core/AddressResolverName.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | #include "lldb/Core/ArchSpec.h" |
| 35 | #include "lldb/Core/Debugger.h" |
| 36 | #include "lldb/Core/Disassembler.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 37 | #include "lldb/Core/Log.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 38 | #include "lldb/Core/Module.h" |
| 39 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Core/RegularExpression.h" |
| 41 | #include "lldb/Core/SearchFilter.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 42 | #include "lldb/Core/Section.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Core/STLUtils.h" |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 44 | #include "lldb/Core/ValueObjectConstResult.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 45 | #include "lldb/Core/ValueObjectList.h" |
| 46 | #include "lldb/Core/ValueObjectVariable.h" |
| 47 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 48 | #include "lldb/Host/Host.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 49 | #include "lldb/Interpreter/Args.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 50 | #include "lldb/Symbol/ObjectFile.h" |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 51 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 52 | #include "lldb/Symbol/VariableList.h" |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 53 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | #include "lldb/Target/Process.h" |
| 55 | #include "lldb/Target/Target.h" |
| 56 | #include "lldb/Target/TargetList.h" |
| 57 | |
| 58 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 59 | #include "../source/Commands/CommandObjectBreakpoint.h" |
| 60 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | |
| 62 | using namespace lldb; |
| 63 | using namespace lldb_private; |
| 64 | |
| 65 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 66 | |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 67 | SBLaunchInfo::SBLaunchInfo (const char **argv) : |
| 68 | m_opaque_sp(new ProcessLaunchInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 69 | { |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 70 | m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR); |
| 71 | if (argv && argv[0]) |
| 72 | m_opaque_sp->GetArguments().SetArguments(argv); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 75 | SBLaunchInfo::~SBLaunchInfo() |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | lldb_private::ProcessLaunchInfo & |
| 80 | SBLaunchInfo::ref () |
| 81 | { |
| 82 | return *m_opaque_sp; |
| 83 | } |
| 84 | |
| 85 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 86 | uint32_t |
| 87 | SBLaunchInfo::GetUserID() |
| 88 | { |
| 89 | return m_opaque_sp->GetUserID(); |
| 90 | } |
| 91 | |
| 92 | uint32_t |
| 93 | SBLaunchInfo::GetGroupID() |
| 94 | { |
| 95 | return m_opaque_sp->GetGroupID(); |
| 96 | } |
| 97 | |
| 98 | bool |
| 99 | SBLaunchInfo::UserIDIsValid () |
| 100 | { |
| 101 | return m_opaque_sp->UserIDIsValid(); |
| 102 | } |
| 103 | |
| 104 | bool |
| 105 | SBLaunchInfo::GroupIDIsValid () |
| 106 | { |
| 107 | return m_opaque_sp->GroupIDIsValid(); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | SBLaunchInfo::SetUserID (uint32_t uid) |
| 112 | { |
| 113 | m_opaque_sp->SetUserID (uid); |
| 114 | } |
| 115 | |
| 116 | void |
| 117 | SBLaunchInfo::SetGroupID (uint32_t gid) |
| 118 | { |
| 119 | m_opaque_sp->SetGroupID (gid); |
| 120 | } |
| 121 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 122 | uint32_t |
| 123 | SBLaunchInfo::GetNumArguments () |
| 124 | { |
| 125 | return m_opaque_sp->GetArguments().GetArgumentCount(); |
| 126 | } |
| 127 | |
| 128 | const char * |
| 129 | SBLaunchInfo::GetArgumentAtIndex (uint32_t idx) |
| 130 | { |
| 131 | return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | SBLaunchInfo::SetArguments (const char **argv, bool append) |
| 136 | { |
| 137 | if (append) |
| 138 | { |
| 139 | if (argv) |
| 140 | m_opaque_sp->GetArguments().AppendArguments(argv); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | if (argv) |
| 145 | m_opaque_sp->GetArguments().SetArguments(argv); |
| 146 | else |
| 147 | m_opaque_sp->GetArguments().Clear(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | uint32_t |
| 152 | SBLaunchInfo::GetNumEnvironmentEntries () |
| 153 | { |
| 154 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); |
| 155 | } |
| 156 | |
| 157 | const char * |
| 158 | SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx) |
| 159 | { |
| 160 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); |
| 161 | } |
| 162 | |
| 163 | void |
| 164 | SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append) |
| 165 | { |
| 166 | if (append) |
| 167 | { |
| 168 | if (envp) |
| 169 | m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp); |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | if (envp) |
| 174 | m_opaque_sp->GetEnvironmentEntries().SetArguments(envp); |
| 175 | else |
| 176 | m_opaque_sp->GetEnvironmentEntries().Clear(); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | void |
| 181 | SBLaunchInfo::Clear () |
| 182 | { |
| 183 | m_opaque_sp->Clear(); |
| 184 | } |
| 185 | |
| 186 | const char * |
| 187 | SBLaunchInfo::GetWorkingDirectory () const |
| 188 | { |
| 189 | return m_opaque_sp->GetWorkingDirectory(); |
| 190 | } |
| 191 | |
| 192 | void |
| 193 | SBLaunchInfo::SetWorkingDirectory (const char *working_dir) |
| 194 | { |
| 195 | m_opaque_sp->SetWorkingDirectory(working_dir); |
| 196 | } |
| 197 | |
| 198 | uint32_t |
| 199 | SBLaunchInfo::GetLaunchFlags () |
| 200 | { |
| 201 | return m_opaque_sp->GetFlags().Get(); |
| 202 | } |
| 203 | |
| 204 | void |
| 205 | SBLaunchInfo::SetLaunchFlags (uint32_t flags) |
| 206 | { |
| 207 | m_opaque_sp->GetFlags().Reset(flags); |
| 208 | } |
| 209 | |
| 210 | const char * |
| 211 | SBLaunchInfo::GetProcessPluginName () |
| 212 | { |
| 213 | return m_opaque_sp->GetProcessPluginName(); |
| 214 | } |
| 215 | |
| 216 | void |
| 217 | SBLaunchInfo::SetProcessPluginName (const char *plugin_name) |
| 218 | { |
| 219 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 220 | } |
| 221 | |
| 222 | const char * |
| 223 | SBLaunchInfo::GetShell () |
| 224 | { |
| 225 | return m_opaque_sp->GetShell(); |
| 226 | } |
| 227 | |
| 228 | void |
| 229 | SBLaunchInfo::SetShell (const char * path) |
| 230 | { |
| 231 | m_opaque_sp->SetShell (path); |
| 232 | } |
| 233 | |
| 234 | uint32_t |
| 235 | SBLaunchInfo::GetResumeCount () |
| 236 | { |
| 237 | return m_opaque_sp->GetResumeCount(); |
| 238 | } |
| 239 | |
| 240 | void |
| 241 | SBLaunchInfo::SetResumeCount (uint32_t c) |
| 242 | { |
| 243 | m_opaque_sp->SetResumeCount (c); |
| 244 | } |
| 245 | |
| 246 | bool |
| 247 | SBLaunchInfo::AddCloseFileAction (int fd) |
| 248 | { |
| 249 | return m_opaque_sp->AppendCloseFileAction(fd); |
| 250 | } |
| 251 | |
| 252 | bool |
| 253 | SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd) |
| 254 | { |
| 255 | return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); |
| 256 | } |
| 257 | |
| 258 | bool |
| 259 | SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write) |
| 260 | { |
| 261 | return m_opaque_sp->AppendOpenFileAction(fd, path, read, write); |
| 262 | } |
| 263 | |
| 264 | bool |
| 265 | SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write) |
| 266 | { |
| 267 | return m_opaque_sp->AppendSuppressFileAction(fd, read, write); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | SBAttachInfo::SBAttachInfo () : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 272 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 273 | { |
| 274 | } |
| 275 | |
| 276 | SBAttachInfo::SBAttachInfo (lldb::pid_t pid) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 277 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 278 | { |
| 279 | m_opaque_sp->SetProcessID (pid); |
| 280 | } |
| 281 | |
| 282 | SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 283 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 284 | { |
| 285 | if (path && path[0]) |
| 286 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 287 | m_opaque_sp->SetWaitForLaunch (wait_for); |
| 288 | } |
| 289 | |
| 290 | SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) : |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 291 | m_opaque_sp (new ProcessAttachInfo()) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 292 | { |
| 293 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 294 | } |
| 295 | |
Greg Clayton | ecc7c0d | 2012-03-07 23:52:51 +0000 | [diff] [blame] | 296 | SBAttachInfo::~SBAttachInfo() |
| 297 | { |
| 298 | } |
| 299 | |
| 300 | lldb_private::ProcessAttachInfo & |
| 301 | SBAttachInfo::ref () |
| 302 | { |
| 303 | return *m_opaque_sp; |
| 304 | } |
| 305 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 306 | SBAttachInfo & |
| 307 | SBAttachInfo::operator = (const SBAttachInfo &rhs) |
| 308 | { |
| 309 | if (this != &rhs) |
| 310 | *m_opaque_sp = *rhs.m_opaque_sp; |
| 311 | return *this; |
| 312 | } |
| 313 | |
| 314 | lldb::pid_t |
| 315 | SBAttachInfo::GetProcessID () |
| 316 | { |
| 317 | return m_opaque_sp->GetProcessID(); |
| 318 | } |
| 319 | |
| 320 | void |
| 321 | SBAttachInfo::SetProcessID (lldb::pid_t pid) |
| 322 | { |
| 323 | m_opaque_sp->SetProcessID (pid); |
| 324 | } |
| 325 | |
| 326 | |
| 327 | uint32_t |
| 328 | SBAttachInfo::GetResumeCount () |
| 329 | { |
| 330 | return m_opaque_sp->GetResumeCount(); |
| 331 | } |
| 332 | |
| 333 | void |
| 334 | SBAttachInfo::SetResumeCount (uint32_t c) |
| 335 | { |
| 336 | m_opaque_sp->SetResumeCount (c); |
| 337 | } |
| 338 | |
| 339 | const char * |
| 340 | SBAttachInfo::GetProcessPluginName () |
| 341 | { |
| 342 | return m_opaque_sp->GetProcessPluginName(); |
| 343 | } |
| 344 | |
| 345 | void |
| 346 | SBAttachInfo::SetProcessPluginName (const char *plugin_name) |
| 347 | { |
| 348 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 349 | } |
| 350 | |
| 351 | void |
| 352 | SBAttachInfo::SetExecutable (const char *path) |
| 353 | { |
| 354 | if (path && path[0]) |
| 355 | m_opaque_sp->GetExecutableFile().SetFile(path, false); |
| 356 | else |
| 357 | m_opaque_sp->GetExecutableFile().Clear(); |
| 358 | } |
| 359 | |
| 360 | void |
| 361 | SBAttachInfo::SetExecutable (SBFileSpec exe_file) |
| 362 | { |
| 363 | if (exe_file.IsValid()) |
| 364 | m_opaque_sp->GetExecutableFile() = exe_file.ref(); |
| 365 | else |
| 366 | m_opaque_sp->GetExecutableFile().Clear(); |
| 367 | } |
| 368 | |
| 369 | bool |
| 370 | SBAttachInfo::GetWaitForLaunch () |
| 371 | { |
| 372 | return m_opaque_sp->GetWaitForLaunch(); |
| 373 | } |
| 374 | |
| 375 | void |
| 376 | SBAttachInfo::SetWaitForLaunch (bool b) |
| 377 | { |
| 378 | m_opaque_sp->SetWaitForLaunch (b); |
| 379 | } |
| 380 | |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 381 | bool |
| 382 | SBAttachInfo::GetIgnoreExisting () |
| 383 | { |
| 384 | return m_opaque_sp->GetIgnoreExisting(); |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | SBAttachInfo::SetIgnoreExisting (bool b) |
| 389 | { |
| 390 | m_opaque_sp->SetIgnoreExisting (b); |
| 391 | } |
| 392 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 393 | uint32_t |
Greg Clayton | 41bd8ac | 2012-02-24 23:56:06 +0000 | [diff] [blame] | 394 | SBAttachInfo::GetUserID() |
| 395 | { |
| 396 | return m_opaque_sp->GetUserID(); |
| 397 | } |
| 398 | |
| 399 | uint32_t |
| 400 | SBAttachInfo::GetGroupID() |
| 401 | { |
| 402 | return m_opaque_sp->GetGroupID(); |
| 403 | } |
| 404 | |
| 405 | bool |
| 406 | SBAttachInfo::UserIDIsValid () |
| 407 | { |
| 408 | return m_opaque_sp->UserIDIsValid(); |
| 409 | } |
| 410 | |
| 411 | bool |
| 412 | SBAttachInfo::GroupIDIsValid () |
| 413 | { |
| 414 | return m_opaque_sp->GroupIDIsValid(); |
| 415 | } |
| 416 | |
| 417 | void |
| 418 | SBAttachInfo::SetUserID (uint32_t uid) |
| 419 | { |
| 420 | m_opaque_sp->SetUserID (uid); |
| 421 | } |
| 422 | |
| 423 | void |
| 424 | SBAttachInfo::SetGroupID (uint32_t gid) |
| 425 | { |
| 426 | m_opaque_sp->SetGroupID (gid); |
| 427 | } |
| 428 | |
| 429 | uint32_t |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 430 | SBAttachInfo::GetEffectiveUserID() |
| 431 | { |
| 432 | return m_opaque_sp->GetEffectiveUserID(); |
| 433 | } |
| 434 | |
| 435 | uint32_t |
| 436 | SBAttachInfo::GetEffectiveGroupID() |
| 437 | { |
| 438 | return m_opaque_sp->GetEffectiveGroupID(); |
| 439 | } |
| 440 | |
| 441 | bool |
| 442 | SBAttachInfo::EffectiveUserIDIsValid () |
| 443 | { |
| 444 | return m_opaque_sp->EffectiveUserIDIsValid(); |
| 445 | } |
| 446 | |
| 447 | bool |
| 448 | SBAttachInfo::EffectiveGroupIDIsValid () |
| 449 | { |
| 450 | return m_opaque_sp->EffectiveGroupIDIsValid (); |
| 451 | } |
| 452 | |
| 453 | void |
| 454 | SBAttachInfo::SetEffectiveUserID (uint32_t uid) |
| 455 | { |
| 456 | m_opaque_sp->SetEffectiveUserID(uid); |
| 457 | } |
| 458 | |
| 459 | void |
| 460 | SBAttachInfo::SetEffectiveGroupID (uint32_t gid) |
| 461 | { |
| 462 | m_opaque_sp->SetEffectiveGroupID(gid); |
| 463 | } |
| 464 | |
| 465 | lldb::pid_t |
| 466 | SBAttachInfo::GetParentProcessID () |
| 467 | { |
| 468 | return m_opaque_sp->GetParentProcessID(); |
| 469 | } |
| 470 | |
| 471 | void |
| 472 | SBAttachInfo::SetParentProcessID (lldb::pid_t pid) |
| 473 | { |
| 474 | m_opaque_sp->SetParentProcessID (pid); |
| 475 | } |
| 476 | |
| 477 | bool |
| 478 | SBAttachInfo::ParentProcessIDIsValid() |
| 479 | { |
| 480 | return m_opaque_sp->ParentProcessIDIsValid(); |
| 481 | } |
| 482 | |
| 483 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | //---------------------------------------------------------------------- |
| 485 | // SBTarget constructor |
| 486 | //---------------------------------------------------------------------- |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 487 | SBTarget::SBTarget () : |
| 488 | m_opaque_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | { |
| 490 | } |
| 491 | |
| 492 | SBTarget::SBTarget (const SBTarget& rhs) : |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 493 | m_opaque_sp (rhs.m_opaque_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | { |
| 495 | } |
| 496 | |
| 497 | SBTarget::SBTarget(const TargetSP& target_sp) : |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 498 | m_opaque_sp (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | { |
| 500 | } |
| 501 | |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 502 | const SBTarget& |
| 503 | SBTarget::operator = (const SBTarget& rhs) |
| 504 | { |
| 505 | if (this != &rhs) |
| 506 | m_opaque_sp = rhs.m_opaque_sp; |
| 507 | return *this; |
| 508 | } |
| 509 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | //---------------------------------------------------------------------- |
| 511 | // Destructor |
| 512 | //---------------------------------------------------------------------- |
| 513 | SBTarget::~SBTarget() |
| 514 | { |
| 515 | } |
| 516 | |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 517 | const char * |
| 518 | SBTarget::GetBroadcasterClassName () |
| 519 | { |
| 520 | return Target::GetStaticBroadcasterClass().AsCString(); |
| 521 | } |
| 522 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 523 | bool |
| 524 | SBTarget::IsValid () const |
| 525 | { |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 526 | return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | SBProcess |
| 530 | SBTarget::GetProcess () |
| 531 | { |
| 532 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 533 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 534 | TargetSP target_sp(GetSP()); |
| 535 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 536 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 537 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 538 | sb_process.SetSP (process_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 539 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 540 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 541 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 542 | if (log) |
| 543 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 544 | log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 545 | target_sp.get(), process_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 548 | return sb_process; |
| 549 | } |
| 550 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 551 | SBDebugger |
| 552 | SBTarget::GetDebugger () const |
| 553 | { |
| 554 | SBDebugger debugger; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 555 | TargetSP target_sp(GetSP()); |
| 556 | if (target_sp) |
| 557 | debugger.reset (target_sp->GetDebugger().shared_from_this()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 558 | return debugger; |
| 559 | } |
| 560 | |
Jim Ingham | 270684d | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 561 | SBProcess |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 562 | SBTarget::LoadCore (const char *core_file) |
| 563 | { |
| 564 | SBProcess sb_process; |
| 565 | TargetSP target_sp(GetSP()); |
| 566 | if (target_sp) |
| 567 | { |
| 568 | FileSpec filespec(core_file, true); |
| 569 | ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(), |
| 570 | NULL, |
| 571 | &filespec)); |
| 572 | if (process_sp) |
| 573 | { |
| 574 | process_sp->LoadCore(); |
| 575 | sb_process.SetSP (process_sp); |
| 576 | } |
| 577 | } |
| 578 | return sb_process; |
| 579 | } |
| 580 | |
| 581 | SBProcess |
Jim Ingham | 270684d | 2011-03-31 00:01:24 +0000 | [diff] [blame] | 582 | SBTarget::LaunchSimple |
| 583 | ( |
| 584 | char const **argv, |
| 585 | char const **envp, |
| 586 | const char *working_directory |
| 587 | ) |
| 588 | { |
| 589 | char *stdin_path = NULL; |
| 590 | char *stdout_path = NULL; |
| 591 | char *stderr_path = NULL; |
| 592 | uint32_t launch_flags = 0; |
| 593 | bool stop_at_entry = false; |
| 594 | SBError error; |
| 595 | SBListener listener = GetDebugger().GetListener(); |
| 596 | return Launch (listener, |
| 597 | argv, |
| 598 | envp, |
| 599 | stdin_path, |
| 600 | stdout_path, |
| 601 | stderr_path, |
| 602 | working_directory, |
| 603 | launch_flags, |
| 604 | stop_at_entry, |
| 605 | error); |
| 606 | } |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 607 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame^] | 608 | SBError |
| 609 | SBTarget::Install() |
| 610 | { |
| 611 | SBError sb_error; |
| 612 | TargetSP target_sp(GetSP()); |
| 613 | if (target_sp) |
| 614 | { |
| 615 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 616 | sb_error.ref() = target_sp->Install(NULL); |
| 617 | } |
| 618 | return sb_error; |
| 619 | } |
| 620 | |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 621 | SBProcess |
| 622 | SBTarget::Launch |
| 623 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 624 | SBListener &listener, |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 625 | char const **argv, |
| 626 | char const **envp, |
| 627 | const char *stdin_path, |
| 628 | const char *stdout_path, |
| 629 | const char *stderr_path, |
| 630 | const char *working_directory, |
| 631 | uint32_t launch_flags, // See LaunchFlags |
| 632 | bool stop_at_entry, |
| 633 | lldb::SBError& error |
| 634 | ) |
| 635 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 636 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 637 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 638 | SBProcess sb_process; |
| 639 | ProcessSP process_sp; |
| 640 | TargetSP target_sp(GetSP()); |
| 641 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 642 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 643 | { |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 644 | 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 | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 645 | target_sp.get(), |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 646 | argv, |
| 647 | envp, |
| 648 | stdin_path ? stdin_path : "NULL", |
| 649 | stdout_path ? stdout_path : "NULL", |
| 650 | stderr_path ? stderr_path : "NULL", |
| 651 | working_directory ? working_directory : "NULL", |
| 652 | launch_flags, |
| 653 | stop_at_entry, |
| 654 | error.get()); |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 655 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 656 | |
| 657 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 658 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 659 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 660 | |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 661 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) |
| 662 | launch_flags |= eLaunchFlagDisableASLR; |
| 663 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 664 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 665 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 666 | if (process_sp) |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 667 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 668 | state = process_sp->GetState(); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 669 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 670 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 671 | { |
| 672 | if (state == eStateAttaching) |
| 673 | error.SetErrorString ("process attach is in progress"); |
| 674 | else |
| 675 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 676 | return sb_process; |
| 677 | } |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 680 | if (state == eStateConnected) |
| 681 | { |
| 682 | // If we are already connected, then we have already specified the |
| 683 | // listener, so if a valid listener is supplied, we need to error out |
| 684 | // to let the client know. |
| 685 | if (listener.IsValid()) |
| 686 | { |
| 687 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 688 | return sb_process; |
| 689 | } |
| 690 | } |
| 691 | else |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 692 | { |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 693 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 694 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 695 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 696 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 697 | } |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 698 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 699 | if (process_sp) |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 700 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 701 | sb_process.SetSP (process_sp); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 702 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) |
| 703 | launch_flags |= eLaunchFlagDisableSTDIO; |
| 704 | |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 705 | ProcessLaunchInfo launch_info (stdin_path, stdout_path, stderr_path, working_directory, launch_flags); |
| 706 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 707 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 708 | if (exe_module) |
Greg Clayton | ad9e828 | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 709 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 982c976 | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 710 | if (argv) |
| 711 | launch_info.GetArguments().AppendArguments (argv); |
| 712 | if (envp) |
| 713 | launch_info.GetEnvironmentEntries ().SetArguments (envp); |
| 714 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 715 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 716 | if (error.Success()) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 717 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 718 | // We we are stopping at the entry point, we can return now! |
| 719 | if (stop_at_entry) |
| 720 | return sb_process; |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 721 | |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 722 | // Make sure we are stopped at the entry |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 723 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 724 | if (state == eStateStopped) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 725 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 726 | // resume the process to skip the entry point |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 727 | error.SetError (process_sp->Resume()); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 728 | if (error.Success()) |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 729 | { |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 730 | // If we are doing synchronous mode, then wait for the |
| 731 | // process to stop yet again! |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 732 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 733 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 645bf54 | 2011-01-27 01:01:10 +0000 | [diff] [blame] | 734 | } |
| 735 | } |
| 736 | } |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 737 | } |
| 738 | else |
| 739 | { |
| 740 | error.SetErrorString ("unable to create lldb_private::Process"); |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | else |
| 744 | { |
| 745 | error.SetErrorString ("SBTarget is invalid"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 747 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 748 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 749 | if (log) |
| 750 | { |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 751 | log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 752 | target_sp.get(), process_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Greg Clayton | 5d5028b | 2010-10-06 03:53:16 +0000 | [diff] [blame] | 755 | return sb_process; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 758 | SBProcess |
| 759 | SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) |
| 760 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 761 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 762 | |
| 763 | SBProcess sb_process; |
| 764 | ProcessSP process_sp; |
| 765 | TargetSP target_sp(GetSP()); |
| 766 | |
| 767 | if (log) |
| 768 | { |
| 769 | log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", target_sp.get()); |
| 770 | } |
| 771 | |
| 772 | if (target_sp) |
| 773 | { |
| 774 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 775 | StateType state = eStateInvalid; |
| 776 | process_sp = target_sp->GetProcessSP(); |
| 777 | if (process_sp) |
| 778 | { |
| 779 | state = process_sp->GetState(); |
| 780 | |
| 781 | if (process_sp->IsAlive() && state != eStateConnected) |
| 782 | { |
| 783 | if (state == eStateAttaching) |
| 784 | error.SetErrorString ("process attach is in progress"); |
| 785 | else |
| 786 | error.SetErrorString ("a process is already being debugged"); |
| 787 | return sb_process; |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | if (state != eStateConnected) |
| 792 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 793 | |
| 794 | if (process_sp) |
| 795 | { |
| 796 | sb_process.SetSP (process_sp); |
| 797 | lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref(); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 798 | |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 799 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 800 | if (exe_module) |
Han Ming Ong | 04cf1ba | 2012-03-02 01:02:04 +0000 | [diff] [blame] | 801 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 802 | |
| 803 | const ArchSpec &arch_spec = target_sp->GetArchitecture(); |
| 804 | if (arch_spec.IsValid()) |
| 805 | launch_info.GetArchitecture () = arch_spec; |
| 806 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 807 | error.SetError (process_sp->Launch (launch_info)); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 808 | const bool synchronous_execution = target_sp->GetDebugger().GetAsyncExecution () == false; |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 809 | if (error.Success()) |
| 810 | { |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 811 | if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 812 | { |
| 813 | // If we are doing synchronous mode, then wait for the initial |
| 814 | // stop to happen, else, return and let the caller watch for |
| 815 | // the stop |
| 816 | if (synchronous_execution) |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 817 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 818 | // We we are stopping at the entry point, we can return now! |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 819 | return sb_process; |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 820 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 821 | |
| 822 | // Make sure we are stopped at the entry |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 823 | StateType state = process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 824 | if (state == eStateStopped) |
| 825 | { |
| 826 | // resume the process to skip the entry point |
| 827 | error.SetError (process_sp->Resume()); |
| 828 | if (error.Success()) |
| 829 | { |
| 830 | // If we are doing synchronous mode, then wait for the |
| 831 | // process to stop yet again! |
Greg Clayton | 38d1f05 | 2012-02-24 20:59:25 +0000 | [diff] [blame] | 832 | if (synchronous_execution) |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 833 | process_sp->WaitForProcessToStop (NULL); |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | else |
| 839 | { |
| 840 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 841 | } |
| 842 | } |
| 843 | else |
| 844 | { |
| 845 | error.SetErrorString ("SBTarget is invalid"); |
| 846 | } |
| 847 | |
| 848 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 849 | if (log) |
| 850 | { |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 851 | log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 852 | target_sp.get(), process_sp.get()); |
| 853 | } |
| 854 | |
| 855 | return sb_process; |
| 856 | } |
| 857 | |
| 858 | lldb::SBProcess |
| 859 | SBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error) |
| 860 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 861 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 862 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 863 | SBProcess sb_process; |
| 864 | ProcessSP process_sp; |
| 865 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 866 | |
| 867 | if (log) |
| 868 | { |
| 869 | log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", target_sp.get()); |
| 870 | } |
| 871 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 872 | if (target_sp) |
| 873 | { |
| 874 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 875 | |
| 876 | StateType state = eStateInvalid; |
| 877 | process_sp = target_sp->GetProcessSP(); |
| 878 | if (process_sp) |
| 879 | { |
| 880 | state = process_sp->GetState(); |
| 881 | |
| 882 | if (process_sp->IsAlive() && state != eStateConnected) |
| 883 | { |
| 884 | if (state == eStateAttaching) |
| 885 | error.SetErrorString ("process attach is in progress"); |
| 886 | else |
| 887 | error.SetErrorString ("a process is already being debugged"); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 888 | if (log) |
| 889 | { |
| 890 | log->Printf ("SBTarget(%p)::Attach (...) => error %s", |
| 891 | target_sp.get(), error.GetCString()); |
| 892 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 893 | return sb_process; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | if (state != eStateConnected) |
| 898 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
| 899 | |
| 900 | if (process_sp) |
| 901 | { |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 902 | ProcessAttachInfo &attach_info = sb_attach_info.ref(); |
Han Ming Ong | fbd8de8 | 2013-03-25 20:11:18 +0000 | [diff] [blame] | 903 | if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 904 | { |
| 905 | PlatformSP platform_sp = target_sp->GetPlatform(); |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 906 | // See if we can pre-verify if a process exists or not |
| 907 | if (platform_sp && platform_sp->IsConnected()) |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 908 | { |
Han Ming Ong | fbd8de8 | 2013-03-25 20:11:18 +0000 | [diff] [blame] | 909 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 910 | ProcessInstanceInfo instance_info; |
| 911 | if (platform_sp->GetProcessInfo(attach_pid, instance_info)) |
| 912 | { |
| 913 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
| 914 | } |
| 915 | else |
| 916 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 917 | error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 918 | if (log) |
| 919 | { |
| 920 | log->Printf ("SBTarget(%p)::Attach (...) => error %s", |
| 921 | target_sp.get(), error.GetCString()); |
| 922 | } |
Greg Clayton | 91e407e | 2012-09-27 00:03:39 +0000 | [diff] [blame] | 923 | return sb_process; |
| 924 | } |
Han Ming Ong | cec8c90 | 2012-02-29 00:12:56 +0000 | [diff] [blame] | 925 | } |
| 926 | } |
Han Ming Ong | bee9839 | 2012-02-29 19:16:40 +0000 | [diff] [blame] | 927 | error.SetError (process_sp->Attach (attach_info)); |
| 928 | if (error.Success()) |
| 929 | { |
| 930 | sb_process.SetSP (process_sp); |
| 931 | // If we are doing synchronous mode, then wait for the |
| 932 | // process to stop! |
| 933 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
| 934 | process_sp->WaitForProcessToStop (NULL); |
| 935 | } |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 936 | } |
| 937 | else |
| 938 | { |
| 939 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 940 | } |
| 941 | } |
| 942 | else |
| 943 | { |
| 944 | error.SetErrorString ("SBTarget is invalid"); |
| 945 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 946 | |
| 947 | if (log) |
| 948 | { |
| 949 | log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)", |
| 950 | target_sp.get(), process_sp.get()); |
| 951 | } |
| 952 | |
Greg Clayton | 0e61568 | 2012-02-24 05:03:03 +0000 | [diff] [blame] | 953 | return sb_process; |
| 954 | } |
| 955 | |
| 956 | |
Greg Clayton | 1ba6cfd | 2011-12-02 02:10:57 +0000 | [diff] [blame] | 957 | #if defined(__APPLE__) |
| 958 | |
| 959 | lldb::SBProcess |
| 960 | SBTarget::AttachToProcessWithID (SBListener &listener, |
| 961 | ::pid_t pid, |
| 962 | lldb::SBError& error) |
| 963 | { |
| 964 | return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); |
| 965 | } |
| 966 | |
| 967 | #endif // #if defined(__APPLE__) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 968 | |
| 969 | lldb::SBProcess |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 970 | SBTarget::AttachToProcessWithID |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 971 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 972 | SBListener &listener, |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 973 | lldb::pid_t pid,// The process ID to attach to |
| 974 | SBError& error // An error explaining what went wrong if attach fails |
| 975 | ) |
| 976 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 977 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 978 | |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 979 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 980 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 981 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 982 | |
| 983 | if (log) |
| 984 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 985 | log->Printf ("SBTarget(%p)::AttachToProcessWithID (listener, pid=%" PRId64 ", error)...", target_sp.get(), pid); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 988 | if (target_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 989 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 990 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 991 | |
| 992 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 993 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 994 | if (process_sp) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 995 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 996 | state = process_sp->GetState(); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 997 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 998 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 999 | { |
| 1000 | if (state == eStateAttaching) |
| 1001 | error.SetErrorString ("process attach is in progress"); |
| 1002 | else |
| 1003 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1004 | return sb_process; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | if (state == eStateConnected) |
| 1009 | { |
| 1010 | // If we are already connected, then we have already specified the |
| 1011 | // listener, so if a valid listener is supplied, we need to error out |
| 1012 | // to let the client know. |
| 1013 | if (listener.IsValid()) |
| 1014 | { |
| 1015 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1016 | return sb_process; |
| 1017 | } |
| 1018 | } |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1019 | else |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1020 | { |
| 1021 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1022 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1023 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1024 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1025 | } |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1026 | if (process_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1027 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1028 | sb_process.SetSP (process_sp); |
| 1029 | |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1030 | ProcessAttachInfo attach_info; |
| 1031 | attach_info.SetProcessID (pid); |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1032 | |
| 1033 | PlatformSP platform_sp = target_sp->GetPlatform(); |
| 1034 | ProcessInstanceInfo instance_info; |
| 1035 | if (platform_sp->GetProcessInfo(pid, instance_info)) |
| 1036 | { |
| 1037 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
Han Ming Ong | 8464704 | 2012-02-25 01:07:38 +0000 | [diff] [blame] | 1038 | } |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1039 | error.SetError (process_sp->Attach (attach_info)); |
Greg Clayton | e2186ed | 2012-09-07 17:51:47 +0000 | [diff] [blame] | 1040 | if (error.Success()) |
| 1041 | { |
| 1042 | // If we are doing synchronous mode, then wait for the |
| 1043 | // process to stop! |
| 1044 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1045 | process_sp->WaitForProcessToStop (NULL); |
Greg Clayton | e2186ed | 2012-09-07 17:51:47 +0000 | [diff] [blame] | 1046 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1047 | } |
| 1048 | else |
| 1049 | { |
| 1050 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1051 | } |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | error.SetErrorString ("SBTarget is invalid"); |
| 1056 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1057 | |
| 1058 | if (log) |
| 1059 | { |
| 1060 | log->Printf ("SBTarget(%p)::AttachToProcessWithID (...) => SBProcess(%p)", |
| 1061 | target_sp.get(), process_sp.get()); |
| 1062 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1063 | return sb_process; |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | lldb::SBProcess |
Greg Clayton | 05faeb7 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 1067 | SBTarget::AttachToProcessWithName |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1068 | ( |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1069 | SBListener &listener, |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1070 | const char *name, // basename of process to attach to |
| 1071 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 1072 | SBError& error // An error explaining what went wrong if attach fails |
| 1073 | ) |
| 1074 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1075 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1076 | |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1077 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1078 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1079 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1080 | |
| 1081 | if (log) |
| 1082 | { |
| 1083 | log->Printf ("SBTarget(%p)::AttachToProcessWithName (listener, name=%s, wait_for=%s, error)...", target_sp.get(), name, wait_for ? "true" : "false"); |
| 1084 | } |
| 1085 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1086 | if (name && target_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1087 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1088 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1089 | |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1090 | StateType state = eStateInvalid; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1091 | process_sp = target_sp->GetProcessSP(); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1092 | if (process_sp) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1093 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1094 | state = process_sp->GetState(); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1095 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1096 | if (process_sp->IsAlive() && state != eStateConnected) |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1097 | { |
| 1098 | if (state == eStateAttaching) |
| 1099 | error.SetErrorString ("process attach is in progress"); |
| 1100 | else |
| 1101 | error.SetErrorString ("a process is already being debugged"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1102 | return sb_process; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | if (state == eStateConnected) |
| 1107 | { |
| 1108 | // If we are already connected, then we have already specified the |
| 1109 | // listener, so if a valid listener is supplied, we need to error out |
| 1110 | // to let the client know. |
| 1111 | if (listener.IsValid()) |
| 1112 | { |
| 1113 | error.SetErrorString ("process is connected and already has a listener, pass empty listener"); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1114 | return sb_process; |
| 1115 | } |
| 1116 | } |
Greg Clayton | 4b04562 | 2011-02-03 21:28:34 +0000 | [diff] [blame] | 1117 | else |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1118 | { |
| 1119 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1120 | process_sp = target_sp->CreateProcess (listener.ref(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1121 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1122 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), NULL, NULL); |
Greg Clayton | 0c74e78 | 2011-06-24 03:21:43 +0000 | [diff] [blame] | 1123 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1124 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1125 | if (process_sp) |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1126 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1127 | sb_process.SetSP (process_sp); |
Greg Clayton | 144f3a9 | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 1128 | ProcessAttachInfo attach_info; |
| 1129 | attach_info.GetExecutableFile().SetFile(name, false); |
| 1130 | attach_info.SetWaitForLaunch(wait_for); |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1131 | error.SetError (process_sp->Attach (attach_info)); |
Daniel Malea | d659dc1 | 2013-04-01 19:47:00 +0000 | [diff] [blame] | 1132 | if (error.Success()) |
| 1133 | { |
| 1134 | // If we are doing synchronous mode, then wait for the |
| 1135 | // process to stop! |
| 1136 | if (target_sp->GetDebugger().GetAsyncExecution () == false) |
| 1137 | process_sp->WaitForProcessToStop (NULL); |
| 1138 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1143 | } |
| 1144 | } |
| 1145 | else |
| 1146 | { |
| 1147 | error.SetErrorString ("SBTarget is invalid"); |
| 1148 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1149 | |
| 1150 | if (log) |
| 1151 | { |
| 1152 | log->Printf ("SBTarget(%p)::AttachToPorcessWithName (...) => SBProcess(%p)", |
| 1153 | target_sp.get(), process_sp.get()); |
| 1154 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1155 | return sb_process; |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1158 | lldb::SBProcess |
| 1159 | SBTarget::ConnectRemote |
| 1160 | ( |
| 1161 | SBListener &listener, |
| 1162 | const char *url, |
| 1163 | const char *plugin_name, |
| 1164 | SBError& error |
| 1165 | ) |
| 1166 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1167 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1168 | |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1169 | SBProcess sb_process; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1170 | ProcessSP process_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1171 | TargetSP target_sp(GetSP()); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1172 | |
| 1173 | if (log) |
| 1174 | { |
| 1175 | log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", target_sp.get(), url, plugin_name); |
| 1176 | } |
| 1177 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1178 | if (target_sp) |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1179 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1180 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1181 | if (listener.IsValid()) |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1182 | process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1183 | else |
Greg Clayton | c3776bf | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1184 | process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1185 | |
| 1186 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1187 | if (process_sp) |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1188 | { |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1189 | sb_process.SetSP (process_sp); |
Jason Molenda | 4bd4e7e | 2012-09-29 04:02:01 +0000 | [diff] [blame] | 1190 | error.SetError (process_sp->ConnectRemote (NULL, url)); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1191 | } |
| 1192 | else |
| 1193 | { |
| 1194 | error.SetErrorString ("unable to create lldb_private::Process"); |
| 1195 | } |
| 1196 | } |
| 1197 | else |
| 1198 | { |
| 1199 | error.SetErrorString ("SBTarget is invalid"); |
| 1200 | } |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 1201 | |
| 1202 | if (log) |
| 1203 | { |
| 1204 | log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)", |
| 1205 | target_sp.get(), process_sp.get()); |
| 1206 | } |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 1207 | return sb_process; |
| 1208 | } |
| 1209 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1210 | SBFileSpec |
| 1211 | SBTarget::GetExecutable () |
| 1212 | { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1213 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | SBFileSpec exe_file_spec; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1215 | TargetSP target_sp(GetSP()); |
| 1216 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1217 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1218 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1219 | if (exe_module) |
| 1220 | exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1221 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1222 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1223 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1224 | if (log) |
| 1225 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1226 | log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1227 | target_sp.get(), exe_file_spec.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1230 | return exe_file_spec; |
| 1231 | } |
| 1232 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1234 | SBTarget::operator == (const SBTarget &rhs) const |
| 1235 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1236 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | bool |
| 1240 | SBTarget::operator != (const SBTarget &rhs) const |
| 1241 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1242 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1245 | lldb::TargetSP |
| 1246 | SBTarget::GetSP () const |
Greg Clayton | 9a37766 | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 1247 | { |
| 1248 | return m_opaque_sp; |
| 1249 | } |
| 1250 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1251 | void |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 1252 | SBTarget::SetSP (const lldb::TargetSP& target_sp) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1253 | { |
| 1254 | m_opaque_sp = target_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1257 | lldb::SBAddress |
| 1258 | SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1259 | { |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1260 | lldb::SBAddress sb_addr; |
| 1261 | Address &addr = sb_addr.ref(); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1262 | TargetSP target_sp(GetSP()); |
| 1263 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1264 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1265 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1266 | if (target_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, addr)) |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1267 | return sb_addr; |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1268 | } |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1269 | |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1270 | // We have a load address that isn't in a section, just return an address |
| 1271 | // with the offset filled in (the address) and the section set to NULL |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1272 | addr.SetRawAddress(vm_addr); |
Greg Clayton | 00e6fbf | 2011-07-22 16:46:35 +0000 | [diff] [blame] | 1273 | return sb_addr; |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1276 | SBSymbolContext |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1277 | SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, |
| 1278 | uint32_t resolve_scope) |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1279 | { |
| 1280 | SBSymbolContext sc; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1281 | if (addr.IsValid()) |
| 1282 | { |
| 1283 | TargetSP target_sp(GetSP()); |
| 1284 | if (target_sp) |
| 1285 | target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); |
| 1286 | } |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 1287 | return sc; |
| 1288 | } |
| 1289 | |
| 1290 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | SBBreakpoint |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1292 | SBTarget::BreakpointCreateByLocation (const char *file, |
| 1293 | uint32_t line) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | { |
Greg Clayton | 7481c20 | 2010-11-08 00:28:40 +0000 | [diff] [blame] | 1295 | return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | SBBreakpoint |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1299 | SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, |
| 1300 | uint32_t line) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1302 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1303 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1304 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1305 | TargetSP target_sp(GetSP()); |
| 1306 | if (target_sp && line != 0) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1307 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1308 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1309 | |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1310 | const LazyBool check_inlines = eLazyBoolCalculate; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1311 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 1312 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1313 | const bool hardware = false; |
| 1314 | *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1315 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1316 | |
| 1317 | if (log) |
| 1318 | { |
| 1319 | SBStream sstr; |
| 1320 | sb_bp.GetDescription (sstr); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1321 | char path[PATH_MAX]; |
| 1322 | sb_file_spec->GetPath (path, sizeof(path)); |
| 1323 | log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1324 | target_sp.get(), |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1325 | path, |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 1326 | line, |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1327 | sb_bp.get(), |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1328 | sstr.GetData()); |
| 1329 | } |
| 1330 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | return sb_bp; |
| 1332 | } |
| 1333 | |
| 1334 | SBBreakpoint |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1335 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
| 1336 | const char *module_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1337 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1338 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1339 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1340 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1341 | TargetSP target_sp(GetSP()); |
| 1342 | if (target_sp.get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1343 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1344 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1345 | |
| 1346 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1347 | const bool hardware = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1348 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | if (module_name && module_name[0]) |
| 1350 | { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1351 | FileSpecList module_spec_list; |
| 1352 | module_spec_list.Append (FileSpec (module_name, false)); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1353 | *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | } |
| 1355 | else |
| 1356 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1357 | *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, skip_prologue, internal, hardware); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1358 | } |
| 1359 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1360 | |
| 1361 | if (log) |
| 1362 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1363 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1364 | target_sp.get(), symbol_name, module_name, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1367 | return sb_bp; |
| 1368 | } |
| 1369 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1370 | lldb::SBBreakpoint |
| 1371 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1372 | const SBFileSpecList &module_list, |
| 1373 | const SBFileSpecList &comp_unit_list) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1374 | { |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1375 | uint32_t name_type_mask = eFunctionNameTypeAuto; |
| 1376 | return BreakpointCreateByName (symbol_name, name_type_mask, module_list, comp_unit_list); |
| 1377 | } |
| 1378 | |
| 1379 | lldb::SBBreakpoint |
| 1380 | SBTarget::BreakpointCreateByName (const char *symbol_name, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1381 | uint32_t name_type_mask, |
| 1382 | const SBFileSpecList &module_list, |
| 1383 | const SBFileSpecList &comp_unit_list) |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1384 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1385 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1386 | |
| 1387 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1388 | TargetSP target_sp(GetSP()); |
| 1389 | if (target_sp && symbol_name && symbol_name[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1390 | { |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1391 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1392 | const bool hardware = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1393 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1394 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1395 | *sb_bp = target_sp->CreateBreakpoint (module_list.get(), |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1396 | comp_unit_list.get(), |
| 1397 | symbol_name, |
| 1398 | name_type_mask, |
| 1399 | skip_prologue, |
| 1400 | internal, |
| 1401 | hardware); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | if (log) |
| 1405 | { |
Jim Ingham | 2dd7f7f | 2011-10-11 01:18:55 +0000 | [diff] [blame] | 1406 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1407 | target_sp.get(), symbol_name, name_type_mask, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | return sb_bp; |
| 1411 | } |
| 1412 | |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1413 | lldb::SBBreakpoint |
| 1414 | SBTarget::BreakpointCreateByNames (const char *symbol_names[], |
| 1415 | uint32_t num_names, |
| 1416 | uint32_t name_type_mask, |
| 1417 | const SBFileSpecList &module_list, |
| 1418 | const SBFileSpecList &comp_unit_list) |
| 1419 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1420 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1421 | |
| 1422 | SBBreakpoint sb_bp; |
| 1423 | TargetSP target_sp(GetSP()); |
| 1424 | if (target_sp && num_names > 0) |
| 1425 | { |
| 1426 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1427 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1428 | const bool hardware = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1429 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1430 | *sb_bp = target_sp->CreateBreakpoint (module_list.get(), |
| 1431 | comp_unit_list.get(), |
| 1432 | symbol_names, |
| 1433 | num_names, |
| 1434 | name_type_mask, |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1435 | skip_prologue, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1436 | internal, |
| 1437 | hardware); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | if (log) |
| 1441 | { |
| 1442 | log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", target_sp.get()); |
| 1443 | for (uint32_t i = 0 ; i < num_names; i++) |
| 1444 | { |
| 1445 | char sep; |
| 1446 | if (i < num_names - 1) |
| 1447 | sep = ','; |
| 1448 | else |
| 1449 | sep = '}'; |
| 1450 | if (symbol_names[i] != NULL) |
| 1451 | log->Printf ("\"%s\"%c ", symbol_names[i], sep); |
| 1452 | else |
| 1453 | log->Printf ("\"<NULL>\"%c ", sep); |
| 1454 | |
| 1455 | } |
| 1456 | log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, sb_bp.get()); |
| 1457 | } |
| 1458 | |
| 1459 | return sb_bp; |
| 1460 | } |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1461 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1462 | SBBreakpoint |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1463 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, |
| 1464 | const char *module_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1465 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1466 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1467 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1468 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1469 | TargetSP target_sp(GetSP()); |
| 1470 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1471 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1472 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1473 | RegularExpression regexp(symbol_name_regex); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1474 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1475 | const bool hardware = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1476 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1477 | |
| 1478 | if (module_name && module_name[0]) |
| 1479 | { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1480 | FileSpecList module_spec_list; |
| 1481 | module_spec_list.Append (FileSpec (module_name, false)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1482 | |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1483 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (&module_spec_list, NULL, regexp, skip_prologue, internal, hardware); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1484 | } |
| 1485 | else |
| 1486 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1487 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (NULL, NULL, regexp, skip_prologue, internal, hardware); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1488 | } |
| 1489 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1490 | |
| 1491 | if (log) |
| 1492 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 1493 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1494 | target_sp.get(), symbol_name_regex, module_name, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1497 | return sb_bp; |
| 1498 | } |
| 1499 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1500 | lldb::SBBreakpoint |
| 1501 | SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1502 | const SBFileSpecList &module_list, |
| 1503 | const SBFileSpecList &comp_unit_list) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1504 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1505 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1506 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1507 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1508 | TargetSP target_sp(GetSP()); |
| 1509 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1510 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1511 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1512 | RegularExpression regexp(symbol_name_regex); |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1513 | const bool internal = false; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1514 | const bool hardware = false; |
Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 1515 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1516 | |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1517 | *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, skip_prologue, internal, hardware); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | if (log) |
| 1521 | { |
| 1522 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1523 | target_sp.get(), symbol_name_regex, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | return sb_bp; |
| 1527 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1528 | |
| 1529 | SBBreakpoint |
| 1530 | SBTarget::BreakpointCreateByAddress (addr_t address) |
| 1531 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1532 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1533 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1534 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1535 | TargetSP target_sp(GetSP()); |
| 1536 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1537 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1538 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1539 | const bool hardware = false; |
| 1540 | *sb_bp = target_sp->CreateBreakpoint (address, false, hardware); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1541 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1542 | |
| 1543 | if (log) |
| 1544 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1545 | log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", target_sp.get(), (uint64_t) address, sb_bp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1548 | return sb_bp; |
| 1549 | } |
| 1550 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1551 | lldb::SBBreakpoint |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1552 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, |
| 1553 | const lldb::SBFileSpec &source_file, |
| 1554 | const char *module_name) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1555 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1556 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1557 | |
| 1558 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1559 | TargetSP target_sp(GetSP()); |
| 1560 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1561 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1562 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1563 | RegularExpression regexp(source_regex); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1564 | FileSpecList source_file_spec_list; |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1565 | const bool hardware = false; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1566 | source_file_spec_list.Append (source_file.ref()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1567 | |
| 1568 | if (module_name && module_name[0]) |
| 1569 | { |
| 1570 | FileSpecList module_spec_list; |
| 1571 | module_spec_list.Append (FileSpec (module_name, false)); |
| 1572 | |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1573 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1574 | } |
| 1575 | else |
| 1576 | { |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1577 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | if (log) |
| 1582 | { |
| 1583 | char path[PATH_MAX]; |
| 1584 | source_file->GetPath (path, sizeof(path)); |
| 1585 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1586 | target_sp.get(), source_regex, path, module_name, sb_bp.get()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | return sb_bp; |
| 1590 | } |
| 1591 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1592 | lldb::SBBreakpoint |
| 1593 | SBTarget::BreakpointCreateBySourceRegex (const char *source_regex, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1594 | const SBFileSpecList &module_list, |
| 1595 | const lldb::SBFileSpecList &source_file_list) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1596 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1597 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1598 | |
| 1599 | SBBreakpoint sb_bp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1600 | TargetSP target_sp(GetSP()); |
| 1601 | if (target_sp && source_regex && source_regex[0]) |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1602 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1603 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1604 | const bool hardware = false; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1605 | RegularExpression regexp(source_regex); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1606 | *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | if (log) |
| 1610 | { |
| 1611 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1612 | target_sp.get(), source_regex, sb_bp.get()); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | return sb_bp; |
| 1616 | } |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1617 | |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1618 | lldb::SBBreakpoint |
| 1619 | SBTarget::BreakpointCreateForException (lldb::LanguageType language, |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1620 | bool catch_bp, |
| 1621 | bool throw_bp) |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1622 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1623 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1624 | |
| 1625 | SBBreakpoint sb_bp; |
| 1626 | TargetSP target_sp(GetSP()); |
| 1627 | if (target_sp) |
| 1628 | { |
| 1629 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | eb023e7 | 2013-10-11 19:48:25 +0000 | [diff] [blame] | 1630 | const bool hardware = false; |
| 1631 | *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware); |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | if (log) |
| 1635 | { |
| 1636 | log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)", |
| 1637 | target_sp.get(), |
| 1638 | LanguageRuntime::GetNameForLanguageType(language), |
| 1639 | catch_bp ? "on" : "off", |
| 1640 | throw_bp ? "on" : "off", |
| 1641 | sb_bp.get()); |
| 1642 | } |
| 1643 | |
| 1644 | return sb_bp; |
| 1645 | } |
| 1646 | |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1647 | uint32_t |
| 1648 | SBTarget::GetNumBreakpoints () const |
| 1649 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1650 | TargetSP target_sp(GetSP()); |
| 1651 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1652 | { |
| 1653 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1654 | return target_sp->GetBreakpointList().GetSize(); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1655 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | SBBreakpoint |
| 1660 | SBTarget::GetBreakpointAtIndex (uint32_t idx) const |
| 1661 | { |
| 1662 | SBBreakpoint sb_breakpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1663 | TargetSP target_sp(GetSP()); |
| 1664 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1665 | { |
| 1666 | // The breakpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1667 | *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1668 | } |
Greg Clayton | 9fed0d8 | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 1669 | return sb_breakpoint; |
| 1670 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1671 | |
| 1672 | bool |
| 1673 | SBTarget::BreakpointDelete (break_id_t bp_id) |
| 1674 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1675 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1676 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1677 | bool result = false; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1678 | TargetSP target_sp(GetSP()); |
| 1679 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1680 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1681 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1682 | result = target_sp->RemoveBreakpointByID (bp_id); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1683 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1684 | |
| 1685 | if (log) |
| 1686 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1687 | log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", target_sp.get(), (uint32_t) bp_id, result); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1693 | SBBreakpoint |
| 1694 | SBTarget::FindBreakpointByID (break_id_t bp_id) |
| 1695 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1696 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1697 | |
| 1698 | SBBreakpoint sb_breakpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1699 | TargetSP target_sp(GetSP()); |
| 1700 | if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1701 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1702 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1703 | *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | if (log) |
| 1707 | { |
| 1708 | log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1709 | target_sp.get(), (uint32_t) bp_id, sb_breakpoint.get()); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | return sb_breakpoint; |
| 1713 | } |
| 1714 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1715 | bool |
| 1716 | SBTarget::EnableAllBreakpoints () |
| 1717 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1718 | TargetSP target_sp(GetSP()); |
| 1719 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1720 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1721 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1722 | target_sp->EnableAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1723 | return true; |
| 1724 | } |
| 1725 | return false; |
| 1726 | } |
| 1727 | |
| 1728 | bool |
| 1729 | SBTarget::DisableAllBreakpoints () |
| 1730 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1731 | TargetSP target_sp(GetSP()); |
| 1732 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1733 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1734 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1735 | target_sp->DisableAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1736 | return true; |
| 1737 | } |
| 1738 | return false; |
| 1739 | } |
| 1740 | |
| 1741 | bool |
| 1742 | SBTarget::DeleteAllBreakpoints () |
| 1743 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1744 | TargetSP target_sp(GetSP()); |
| 1745 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1746 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1747 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 1748 | target_sp->RemoveAllBreakpoints (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | return true; |
| 1750 | } |
| 1751 | return false; |
| 1752 | } |
| 1753 | |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1754 | uint32_t |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1755 | SBTarget::GetNumWatchpoints () const |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1756 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1757 | TargetSP target_sp(GetSP()); |
| 1758 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1759 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1760 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1761 | return target_sp->GetWatchpointList().GetSize(); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1762 | } |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1766 | SBWatchpoint |
| 1767 | SBTarget::GetWatchpointAtIndex (uint32_t idx) const |
Johnny Chen | 9d954d8 | 2011-09-27 20:29:45 +0000 | [diff] [blame] | 1768 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1769 | SBWatchpoint sb_watchpoint; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1770 | TargetSP target_sp(GetSP()); |
| 1771 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1772 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1773 | // The watchpoint list is thread safe, no need to lock |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1774 | sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1775 | } |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1776 | return sb_watchpoint; |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1780 | SBTarget::DeleteWatchpoint (watch_id_t wp_id) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1781 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1782 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1783 | |
| 1784 | bool result = false; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1785 | TargetSP target_sp(GetSP()); |
| 1786 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1787 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1788 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1789 | Mutex::Locker locker; |
| 1790 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1791 | result = target_sp->RemoveWatchpointByID (wp_id); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | if (log) |
| 1795 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1796 | log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", target_sp.get(), (uint32_t) wp_id, result); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | return result; |
| 1800 | } |
| 1801 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1802 | SBWatchpoint |
| 1803 | SBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1804 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1805 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1806 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1807 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1808 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1809 | TargetSP target_sp(GetSP()); |
| 1810 | if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1811 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1812 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1813 | Mutex::Locker locker; |
| 1814 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1815 | watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); |
| 1816 | sb_watchpoint.SetSP (watchpoint_sp); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | if (log) |
| 1820 | { |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1821 | log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1822 | target_sp.get(), (uint32_t) wp_id, watchpoint_sp.get()); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1825 | return sb_watchpoint; |
| 1826 | } |
| 1827 | |
| 1828 | lldb::SBWatchpoint |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1829 | SBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error) |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1830 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1831 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1832 | |
| 1833 | SBWatchpoint sb_watchpoint; |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1834 | lldb::WatchpointSP watchpoint_sp; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1835 | TargetSP target_sp(GetSP()); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1836 | if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1837 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1838 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1839 | uint32_t watch_type = 0; |
| 1840 | if (read) |
| 1841 | watch_type |= LLDB_WATCH_TYPE_READ; |
| 1842 | if (write) |
| 1843 | watch_type |= LLDB_WATCH_TYPE_WRITE; |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 1844 | if (watch_type == 0) |
| 1845 | { |
| 1846 | error.SetErrorString("Can't create a watchpoint that is neither read nor write."); |
| 1847 | return sb_watchpoint; |
| 1848 | } |
| 1849 | |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1850 | // Target::CreateWatchpoint() is thread safe. |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1851 | Error cw_error; |
Jim Ingham | a7dfb66 | 2012-10-23 07:20:06 +0000 | [diff] [blame] | 1852 | // This API doesn't take in a type, so we can't figure out what it is. |
| 1853 | ClangASTType *type = NULL; |
| 1854 | watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 1855 | error.SetError(cw_error); |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1856 | sb_watchpoint.SetSP (watchpoint_sp); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | if (log) |
| 1860 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1861 | log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)", |
Greg Clayton | 81e871e | 2012-02-04 02:27:34 +0000 | [diff] [blame] | 1862 | target_sp.get(), addr, (uint32_t) size, watchpoint_sp.get()); |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | return sb_watchpoint; |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1869 | SBTarget::EnableAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1870 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1871 | TargetSP target_sp(GetSP()); |
| 1872 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1873 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1874 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1875 | Mutex::Locker locker; |
| 1876 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1877 | target_sp->EnableAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1878 | return true; |
| 1879 | } |
| 1880 | return false; |
| 1881 | } |
| 1882 | |
| 1883 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1884 | SBTarget::DisableAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1885 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1886 | TargetSP target_sp(GetSP()); |
| 1887 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1888 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1889 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1890 | Mutex::Locker locker; |
| 1891 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1892 | target_sp->DisableAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1893 | return true; |
| 1894 | } |
| 1895 | return false; |
| 1896 | } |
| 1897 | |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 1898 | SBValue |
| 1899 | SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type) |
| 1900 | { |
| 1901 | SBValue sb_value; |
| 1902 | lldb::ValueObjectSP new_value_sp; |
| 1903 | if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) |
| 1904 | { |
| 1905 | lldb::addr_t address(addr.GetLoadAddress(*this)); |
| 1906 | lldb::TypeImplSP type_impl_sp (type.GetSP()); |
Enrico Granata | dc4db5a | 2013-10-29 00:28:35 +0000 | [diff] [blame] | 1907 | ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ()); |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 1908 | if (pointer_ast_type) |
| 1909 | { |
| 1910 | lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); |
| 1911 | |
| 1912 | ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); |
| 1913 | ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), |
| 1914 | pointer_ast_type, |
| 1915 | ConstString(name), |
| 1916 | buffer, |
| 1917 | exe_ctx.GetByteOrder(), |
| 1918 | exe_ctx.GetAddressByteSize())); |
| 1919 | |
| 1920 | if (ptr_result_valobj_sp) |
| 1921 | { |
| 1922 | ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); |
| 1923 | Error err; |
| 1924 | new_value_sp = ptr_result_valobj_sp->Dereference(err); |
| 1925 | if (new_value_sp) |
| 1926 | new_value_sp->SetName(ConstString(name)); |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | sb_value.SetSP(new_value_sp); |
| 1931 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1932 | if (log) |
| 1933 | { |
| 1934 | if (new_value_sp) |
| 1935 | log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", m_opaque_sp.get(), new_value_sp->GetName().AsCString()); |
| 1936 | else |
| 1937 | log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", m_opaque_sp.get()); |
| 1938 | } |
| 1939 | return sb_value; |
| 1940 | } |
| 1941 | |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1942 | bool |
Greg Clayton | 1b282f9 | 2011-10-13 18:08:26 +0000 | [diff] [blame] | 1943 | SBTarget::DeleteAllWatchpoints () |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1944 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1945 | TargetSP target_sp(GetSP()); |
| 1946 | if (target_sp) |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1947 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1948 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
Johnny Chen | 7385a5a | 2012-05-31 22:56:36 +0000 | [diff] [blame] | 1949 | Mutex::Locker locker; |
| 1950 | target_sp->GetWatchpointList().GetListMutex(locker); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1951 | target_sp->RemoveAllWatchpoints (); |
Johnny Chen | 5d04346 | 2011-09-26 22:40:50 +0000 | [diff] [blame] | 1952 | return true; |
| 1953 | } |
| 1954 | return false; |
| 1955 | } |
| 1956 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1957 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1958 | lldb::SBModule |
| 1959 | SBTarget::AddModule (const char *path, |
| 1960 | const char *triple, |
| 1961 | const char *uuid_cstr) |
| 1962 | { |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1963 | return AddModule (path, triple, uuid_cstr, NULL); |
| 1964 | } |
| 1965 | |
| 1966 | lldb::SBModule |
| 1967 | SBTarget::AddModule (const char *path, |
| 1968 | const char *triple, |
| 1969 | const char *uuid_cstr, |
| 1970 | const char *symfile) |
| 1971 | { |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1972 | lldb::SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 1973 | TargetSP target_sp(GetSP()); |
| 1974 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1975 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1976 | ModuleSpec module_spec; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1977 | if (path) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1978 | module_spec.GetFileSpec().SetFile(path, false); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1979 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1980 | if (uuid_cstr) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 1981 | module_spec.GetUUID().SetFromCString(uuid_cstr); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1982 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1983 | if (triple) |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1984 | module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get()); |
Jason Molenda | b019cd9 | 2013-09-11 21:25:46 +0000 | [diff] [blame] | 1985 | else |
| 1986 | module_spec.GetArchitecture() = target_sp->GetArchitecture(); |
Greg Clayton | b210aec | 2012-04-23 20:23:39 +0000 | [diff] [blame] | 1987 | |
| 1988 | if (symfile) |
| 1989 | module_spec.GetSymbolFileSpec ().SetFile(symfile, false); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1990 | |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 1991 | sb_module.SetSP(target_sp->GetSharedModule (module_spec)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1992 | } |
| 1993 | return sb_module; |
| 1994 | } |
| 1995 | |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 1996 | lldb::SBModule |
| 1997 | SBTarget::AddModule (const SBModuleSpec &module_spec) |
| 1998 | { |
| 1999 | lldb::SBModule sb_module; |
| 2000 | TargetSP target_sp(GetSP()); |
| 2001 | if (target_sp) |
| 2002 | sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap)); |
| 2003 | return sb_module; |
| 2004 | } |
| 2005 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2006 | bool |
| 2007 | SBTarget::AddModule (lldb::SBModule &module) |
| 2008 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2009 | TargetSP target_sp(GetSP()); |
| 2010 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2011 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2012 | target_sp->GetImages().AppendIfNeeded (module.GetSP()); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2013 | return true; |
| 2014 | } |
| 2015 | return false; |
| 2016 | } |
| 2017 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2018 | uint32_t |
| 2019 | SBTarget::GetNumModules () const |
| 2020 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2021 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2022 | |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2023 | uint32_t num = 0; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2024 | TargetSP target_sp(GetSP()); |
| 2025 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2026 | { |
| 2027 | // The module list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2028 | num = target_sp->GetImages().GetSize(); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2029 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2030 | |
| 2031 | if (log) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2032 | log->Printf ("SBTarget(%p)::GetNumModules () => %d", target_sp.get(), num); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2033 | |
| 2034 | return num; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 2037 | void |
| 2038 | SBTarget::Clear () |
| 2039 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2040 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2041 | |
| 2042 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 2043 | log->Printf ("SBTarget(%p)::Clear ()", m_opaque_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2044 | |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 2045 | m_opaque_sp.reset(); |
| 2046 | } |
| 2047 | |
| 2048 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2049 | SBModule |
| 2050 | SBTarget::FindModule (const SBFileSpec &sb_file_spec) |
| 2051 | { |
| 2052 | SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2053 | TargetSP target_sp(GetSP()); |
| 2054 | if (target_sp && sb_file_spec.IsValid()) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2055 | { |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2056 | ModuleSpec module_spec(*sb_file_spec); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2057 | // The module list is thread safe, no need to lock |
Greg Clayton | b9a01b3 | 2012-02-26 05:51:37 +0000 | [diff] [blame] | 2058 | sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec)); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2059 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2060 | return sb_module; |
| 2061 | } |
| 2062 | |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2063 | lldb::ByteOrder |
| 2064 | SBTarget::GetByteOrder () |
| 2065 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2066 | TargetSP target_sp(GetSP()); |
| 2067 | if (target_sp) |
| 2068 | return target_sp->GetArchitecture().GetByteOrder(); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2069 | return eByteOrderInvalid; |
| 2070 | } |
| 2071 | |
| 2072 | const char * |
| 2073 | SBTarget::GetTriple () |
| 2074 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2075 | TargetSP target_sp(GetSP()); |
| 2076 | if (target_sp) |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2077 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2078 | std::string triple (target_sp->GetArchitecture().GetTriple().str()); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2079 | // Unique the string so we don't run into ownership issues since |
| 2080 | // the const strings put the string into the string pool once and |
| 2081 | // the strings never comes out |
| 2082 | ConstString const_triple (triple.c_str()); |
| 2083 | return const_triple.GetCString(); |
| 2084 | } |
| 2085 | return NULL; |
| 2086 | } |
| 2087 | |
| 2088 | uint32_t |
| 2089 | SBTarget::GetAddressByteSize() |
| 2090 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2091 | TargetSP target_sp(GetSP()); |
| 2092 | if (target_sp) |
| 2093 | return target_sp->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | 13d1950 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 2094 | return sizeof(void*); |
| 2095 | } |
| 2096 | |
| 2097 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2098 | SBModule |
| 2099 | SBTarget::GetModuleAtIndex (uint32_t idx) |
| 2100 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2101 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2102 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2103 | SBModule sb_module; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2104 | ModuleSP module_sp; |
| 2105 | TargetSP target_sp(GetSP()); |
| 2106 | if (target_sp) |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2107 | { |
| 2108 | // The module list is thread safe, no need to lock |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2109 | module_sp = target_sp->GetImages().GetModuleAtIndex(idx); |
| 2110 | sb_module.SetSP (module_sp); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 2111 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2112 | |
| 2113 | if (log) |
| 2114 | { |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 2115 | log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2116 | target_sp.get(), idx, module_sp.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2119 | return sb_module; |
| 2120 | } |
| 2121 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2122 | bool |
| 2123 | SBTarget::RemoveModule (lldb::SBModule module) |
| 2124 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2125 | TargetSP target_sp(GetSP()); |
| 2126 | if (target_sp) |
| 2127 | return target_sp->GetImages().Remove(module.GetSP()); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2128 | return false; |
| 2129 | } |
| 2130 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2131 | |
| 2132 | SBBroadcaster |
| 2133 | SBTarget::GetBroadcaster () const |
| 2134 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2135 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2136 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2137 | TargetSP target_sp(GetSP()); |
| 2138 | SBBroadcaster broadcaster(target_sp.get(), false); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2139 | |
| 2140 | if (log) |
Greg Clayton | 93aa84e | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 2141 | log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2142 | target_sp.get(), broadcaster.get()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2143 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2144 | return broadcaster; |
| 2145 | } |
| 2146 | |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 2147 | bool |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2148 | SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 2149 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 2150 | Stream &strm = description.ref(); |
| 2151 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2152 | TargetSP target_sp(GetSP()); |
| 2153 | if (target_sp) |
Caroline Tice | 201a885 | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 2154 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2155 | target_sp->Dump (&strm, description_level); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2156 | } |
| 2157 | else |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 2158 | strm.PutCString ("No value"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 2159 | |
| 2160 | return true; |
| 2161 | } |
| 2162 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2163 | lldb::SBSymbolContextList |
| 2164 | SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2165 | { |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2166 | lldb::SBSymbolContextList sb_sc_list; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2167 | if (name && name[0]) |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2168 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2169 | TargetSP target_sp(GetSP()); |
| 2170 | if (target_sp) |
| 2171 | { |
| 2172 | const bool symbols_ok = true; |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2173 | const bool inlines_ok = true; |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2174 | const bool append = true; |
| 2175 | target_sp->GetImages().FindFunctions (ConstString(name), |
| 2176 | name_type_mask, |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 2177 | symbols_ok, |
| 2178 | inlines_ok, |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2179 | append, |
| 2180 | *sb_sc_list); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2181 | } |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2182 | } |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 2183 | return sb_sc_list; |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2186 | lldb::SBType |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2187 | SBTarget::FindFirstType (const char* typename_cstr) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2188 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2189 | TargetSP target_sp(GetSP()); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2190 | if (typename_cstr && typename_cstr[0] && target_sp) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2191 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2192 | ConstString const_typename(typename_cstr); |
| 2193 | SymbolContext sc; |
| 2194 | const bool exact_match = false; |
| 2195 | |
| 2196 | const ModuleList &module_list = target_sp->GetImages(); |
| 2197 | size_t count = module_list.GetSize(); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2198 | for (size_t idx = 0; idx < count; idx++) |
| 2199 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2200 | ModuleSP module_sp (module_list.GetModuleAtIndex(idx)); |
| 2201 | if (module_sp) |
| 2202 | { |
| 2203 | TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match)); |
| 2204 | if (type_sp) |
| 2205 | return SBType(type_sp); |
| 2206 | } |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2207 | } |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 2208 | |
| 2209 | // Didn't find the type in the symbols; try the Objective-C runtime |
| 2210 | // if one is installed |
| 2211 | |
| 2212 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2213 | |
| 2214 | if (process_sp) |
| 2215 | { |
| 2216 | ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); |
| 2217 | |
| 2218 | if (objc_language_runtime) |
| 2219 | { |
| 2220 | TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); |
| 2221 | |
| 2222 | if (objc_type_vendor) |
| 2223 | { |
| 2224 | std::vector <ClangASTType> types; |
| 2225 | |
| 2226 | if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0) |
| 2227 | return SBType(types[0]); |
| 2228 | } |
| 2229 | } |
| 2230 | } |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2231 | |
| 2232 | // No matches, search for basic typename matches |
| 2233 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2234 | if (clang_ast) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2235 | return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2236 | } |
| 2237 | return SBType(); |
| 2238 | } |
| 2239 | |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2240 | SBType |
| 2241 | SBTarget::GetBasicType(lldb::BasicType type) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2242 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2243 | TargetSP target_sp(GetSP()); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2244 | if (target_sp) |
| 2245 | { |
| 2246 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2247 | if (clang_ast) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2248 | return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type)); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2249 | } |
| 2250 | return SBType(); |
| 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | lldb::SBTypeList |
| 2255 | SBTarget::FindTypes (const char* typename_cstr) |
| 2256 | { |
| 2257 | SBTypeList sb_type_list; |
| 2258 | TargetSP target_sp(GetSP()); |
| 2259 | if (typename_cstr && typename_cstr[0] && target_sp) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2260 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2261 | ModuleList& images = target_sp->GetImages(); |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2262 | ConstString const_typename(typename_cstr); |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2263 | bool exact_match = false; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2264 | SymbolContext sc; |
| 2265 | TypeList type_list; |
| 2266 | |
Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 2267 | uint32_t num_matches = images.FindTypes (sc, |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2268 | const_typename, |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 2269 | exact_match, |
| 2270 | UINT32_MAX, |
| 2271 | type_list); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2272 | |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2273 | if (num_matches > 0) |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2274 | { |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2275 | for (size_t idx = 0; idx < num_matches; idx++) |
| 2276 | { |
| 2277 | TypeSP type_sp (type_list.GetTypeAtIndex(idx)); |
| 2278 | if (type_sp) |
| 2279 | sb_type_list.Append(SBType(type_sp)); |
| 2280 | } |
| 2281 | } |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 2282 | |
| 2283 | // Try the Objective-C runtime if one is installed |
| 2284 | |
| 2285 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2286 | |
| 2287 | if (process_sp) |
| 2288 | { |
| 2289 | ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); |
| 2290 | |
| 2291 | if (objc_language_runtime) |
| 2292 | { |
| 2293 | TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); |
| 2294 | |
| 2295 | if (objc_type_vendor) |
| 2296 | { |
| 2297 | std::vector <ClangASTType> types; |
| 2298 | |
| 2299 | if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types)) |
| 2300 | { |
| 2301 | for (ClangASTType &type : types) |
| 2302 | { |
| 2303 | sb_type_list.Append(SBType(type)); |
| 2304 | } |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | if (sb_type_list.GetSize() == 0) |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2311 | { |
| 2312 | // No matches, search for basic typename matches |
| 2313 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 2314 | if (clang_ast) |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 2315 | sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename))); |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2316 | } |
| 2317 | } |
Greg Clayton | b43165b | 2012-12-05 21:24:42 +0000 | [diff] [blame] | 2318 | return sb_type_list; |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2321 | SBValueList |
| 2322 | SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) |
| 2323 | { |
| 2324 | SBValueList sb_value_list; |
| 2325 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2326 | TargetSP target_sp(GetSP()); |
| 2327 | if (name && target_sp) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2328 | { |
| 2329 | VariableList variable_list; |
| 2330 | const bool append = true; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2331 | const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), |
| 2332 | append, |
| 2333 | max_matches, |
| 2334 | variable_list); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2335 | |
| 2336 | if (match_count > 0) |
| 2337 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2338 | ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2339 | if (exe_scope == NULL) |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2340 | exe_scope = target_sp.get(); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2341 | for (uint32_t i=0; i<match_count; ++i) |
| 2342 | { |
| 2343 | lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); |
| 2344 | if (valobj_sp) |
Enrico Granata | 85425d7 | 2013-02-07 18:23:56 +0000 | [diff] [blame] | 2345 | sb_value_list.Append(SBValue(valobj_sp)); |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | return sb_value_list; |
| 2351 | } |
| 2352 | |
Enrico Granata | bcd80b4 | 2013-01-16 18:53:52 +0000 | [diff] [blame] | 2353 | lldb::SBValue |
| 2354 | SBTarget::FindFirstGlobalVariable (const char* name) |
| 2355 | { |
| 2356 | SBValueList sb_value_list(FindGlobalVariables(name, 1)); |
| 2357 | if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) |
| 2358 | return sb_value_list.GetValueAtIndex(0); |
| 2359 | return SBValue(); |
| 2360 | } |
| 2361 | |
Jim Ingham | e37d605 | 2011-09-13 00:29:56 +0000 | [diff] [blame] | 2362 | SBSourceManager |
| 2363 | SBTarget::GetSourceManager() |
| 2364 | { |
| 2365 | SBSourceManager source_manager (*this); |
| 2366 | return source_manager; |
| 2367 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2368 | |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2369 | lldb::SBInstructionList |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2370 | SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count) |
| 2371 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2372 | return ReadInstructions (base_addr, count, NULL); |
| 2373 | } |
| 2374 | |
| 2375 | lldb::SBInstructionList |
| 2376 | SBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string) |
| 2377 | { |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2378 | SBInstructionList sb_instructions; |
| 2379 | |
| 2380 | TargetSP target_sp(GetSP()); |
| 2381 | if (target_sp) |
| 2382 | { |
| 2383 | Address *addr_ptr = base_addr.get(); |
| 2384 | |
| 2385 | if (addr_ptr) |
| 2386 | { |
| 2387 | DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); |
| 2388 | bool prefer_file_cache = false; |
| 2389 | lldb_private::Error error; |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2390 | lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 2391 | const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, |
| 2392 | prefer_file_cache, |
| 2393 | data.GetBytes(), |
| 2394 | data.GetByteSize(), |
| 2395 | error, |
| 2396 | &load_addr); |
| 2397 | const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2398 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), |
| 2399 | NULL, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2400 | flavor_string, |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2401 | *addr_ptr, |
| 2402 | data.GetBytes(), |
| 2403 | bytes_read, |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2404 | count, |
| 2405 | data_from_file)); |
Greg Clayton | 9c76611 | 2012-03-06 22:24:44 +0000 | [diff] [blame] | 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | return sb_instructions; |
| 2410 | |
| 2411 | } |
| 2412 | |
| 2413 | lldb::SBInstructionList |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2414 | SBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) |
| 2415 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2416 | return GetInstructionsWithFlavor (base_addr, NULL, buf, size); |
| 2417 | } |
| 2418 | |
| 2419 | lldb::SBInstructionList |
| 2420 | SBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size) |
| 2421 | { |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2422 | SBInstructionList sb_instructions; |
| 2423 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2424 | TargetSP target_sp(GetSP()); |
| 2425 | if (target_sp) |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2426 | { |
| 2427 | Address addr; |
| 2428 | |
| 2429 | if (base_addr.get()) |
| 2430 | addr = *base_addr.get(); |
| 2431 | |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2432 | const bool data_from_file = true; |
| 2433 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2434 | sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2435 | NULL, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2436 | flavor_string, |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2437 | addr, |
| 2438 | buf, |
Greg Clayton | 3faf47c | 2013-03-28 23:42:53 +0000 | [diff] [blame] | 2439 | size, |
| 2440 | UINT32_MAX, |
| 2441 | data_from_file)); |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | return sb_instructions; |
| 2445 | } |
| 2446 | |
| 2447 | lldb::SBInstructionList |
| 2448 | SBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) |
| 2449 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 2450 | return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size); |
| 2451 | } |
| 2452 | |
| 2453 | lldb::SBInstructionList |
| 2454 | SBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size) |
| 2455 | { |
| 2456 | return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size); |
Sean Callanan | 50952e9 | 2011-12-14 23:49:37 +0000 | [diff] [blame] | 2457 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2458 | |
| 2459 | SBError |
| 2460 | SBTarget::SetSectionLoadAddress (lldb::SBSection section, |
| 2461 | lldb::addr_t section_base_addr) |
| 2462 | { |
| 2463 | SBError sb_error; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2464 | TargetSP target_sp(GetSP()); |
| 2465 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2466 | { |
| 2467 | if (!section.IsValid()) |
| 2468 | { |
| 2469 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 2470 | } |
| 2471 | else |
| 2472 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2473 | SectionSP section_sp (section.GetSP()); |
| 2474 | if (section_sp) |
| 2475 | { |
| 2476 | if (section_sp->IsThreadSpecific()) |
| 2477 | { |
| 2478 | sb_error.SetErrorString ("thread specific sections are not yet supported"); |
| 2479 | } |
| 2480 | else |
| 2481 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2482 | if (target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr)) |
| 2483 | { |
| 2484 | // Flush info in the process (stack frames, etc) |
| 2485 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2486 | if (process_sp) |
| 2487 | process_sp->Flush(); |
| 2488 | } |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2489 | } |
| 2490 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2491 | } |
| 2492 | } |
| 2493 | else |
| 2494 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2495 | sb_error.SetErrorString ("invalid target"); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2496 | } |
| 2497 | return sb_error; |
| 2498 | } |
| 2499 | |
| 2500 | SBError |
| 2501 | SBTarget::ClearSectionLoadAddress (lldb::SBSection section) |
| 2502 | { |
| 2503 | SBError sb_error; |
| 2504 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2505 | TargetSP target_sp(GetSP()); |
| 2506 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2507 | { |
| 2508 | if (!section.IsValid()) |
| 2509 | { |
| 2510 | sb_error.SetErrorStringWithFormat ("invalid section"); |
| 2511 | } |
| 2512 | else |
| 2513 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2514 | if (target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP())) |
| 2515 | { |
| 2516 | // Flush info in the process (stack frames, etc) |
| 2517 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2518 | if (process_sp) |
| 2519 | process_sp->Flush(); |
| 2520 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2521 | } |
| 2522 | } |
| 2523 | else |
| 2524 | { |
| 2525 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2526 | } |
| 2527 | return sb_error; |
| 2528 | } |
| 2529 | |
| 2530 | SBError |
| 2531 | SBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) |
| 2532 | { |
| 2533 | SBError sb_error; |
| 2534 | |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2535 | TargetSP target_sp(GetSP()); |
| 2536 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2537 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2538 | ModuleSP module_sp (module.GetSP()); |
| 2539 | if (module_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2540 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2541 | bool changed = false; |
| 2542 | if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed)) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2543 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2544 | // The load was successful, make sure that at least some sections |
| 2545 | // changed before we notify that our module was loaded. |
| 2546 | if (changed) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2547 | { |
Greg Clayton | 741f3f9 | 2012-03-27 21:10:07 +0000 | [diff] [blame] | 2548 | ModuleList module_list; |
| 2549 | module_list.Append(module_sp); |
| 2550 | target_sp->ModulesDidLoad (module_list); |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2551 | // Flush info in the process (stack frames, etc) |
| 2552 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2553 | if (process_sp) |
| 2554 | process_sp->Flush(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2555 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2556 | } |
| 2557 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2558 | else |
| 2559 | { |
| 2560 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 2561 | } |
| 2562 | |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2563 | } |
| 2564 | else |
| 2565 | { |
| 2566 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2567 | } |
| 2568 | return sb_error; |
| 2569 | } |
| 2570 | |
| 2571 | SBError |
| 2572 | SBTarget::ClearModuleLoadAddress (lldb::SBModule module) |
| 2573 | { |
| 2574 | SBError sb_error; |
| 2575 | |
| 2576 | char path[PATH_MAX]; |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2577 | TargetSP target_sp(GetSP()); |
| 2578 | if (target_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2579 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2580 | ModuleSP module_sp (module.GetSP()); |
| 2581 | if (module_sp) |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2582 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2583 | ObjectFile *objfile = module_sp->GetObjectFile(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2584 | if (objfile) |
| 2585 | { |
| 2586 | SectionList *section_list = objfile->GetSectionList(); |
| 2587 | if (section_list) |
| 2588 | { |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2589 | bool changed = false; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2590 | const size_t num_sections = section_list->GetSize(); |
| 2591 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) |
| 2592 | { |
| 2593 | SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); |
| 2594 | if (section_sp) |
Greg Clayton | 3c94737 | 2013-01-29 01:17:09 +0000 | [diff] [blame] | 2595 | changed |= target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp) > 0; |
| 2596 | } |
| 2597 | if (changed) |
| 2598 | { |
| 2599 | // Flush info in the process (stack frames, etc) |
| 2600 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2601 | if (process_sp) |
| 2602 | process_sp->Flush(); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2603 | } |
| 2604 | } |
| 2605 | else |
| 2606 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2607 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2608 | sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); |
| 2609 | } |
| 2610 | } |
| 2611 | else |
| 2612 | { |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2613 | module_sp->GetFileSpec().GetPath (path, sizeof(path)); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2614 | sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); |
| 2615 | } |
| 2616 | } |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 2617 | else |
| 2618 | { |
| 2619 | sb_error.SetErrorStringWithFormat ("invalid module"); |
| 2620 | } |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 2621 | } |
| 2622 | else |
| 2623 | { |
| 2624 | sb_error.SetErrorStringWithFormat ("invalid target"); |
| 2625 | } |
| 2626 | return sb_error; |
| 2627 | } |
| 2628 | |
| 2629 | |
Greg Clayton | e14e192 | 2012-12-04 02:22:16 +0000 | [diff] [blame] | 2630 | lldb::SBSymbolContextList |
| 2631 | SBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type) |
| 2632 | { |
| 2633 | SBSymbolContextList sb_sc_list; |
| 2634 | if (name && name[0]) |
| 2635 | { |
| 2636 | TargetSP target_sp(GetSP()); |
| 2637 | if (target_sp) |
| 2638 | { |
| 2639 | bool append = true; |
| 2640 | target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name), |
| 2641 | symbol_type, |
| 2642 | *sb_sc_list, |
| 2643 | append); |
| 2644 | } |
| 2645 | } |
| 2646 | return sb_sc_list; |
| 2647 | |
| 2648 | } |
| 2649 | |
| 2650 | |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2651 | lldb::SBValue |
| 2652 | SBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options) |
| 2653 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 2654 | Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 2655 | Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2656 | SBValue expr_result; |
| 2657 | ExecutionResults exe_results = eExecutionSetupError; |
| 2658 | ValueObjectSP expr_value_sp; |
| 2659 | TargetSP target_sp(GetSP()); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 2660 | StackFrame *frame = NULL; |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2661 | if (target_sp) |
| 2662 | { |
| 2663 | if (expr == NULL || expr[0] == '\0') |
| 2664 | { |
| 2665 | if (log) |
| 2666 | log->Printf ("SBTarget::EvaluateExpression called with an empty expression"); |
| 2667 | return expr_result; |
| 2668 | } |
| 2669 | |
| 2670 | Mutex::Locker api_locker (target_sp->GetAPIMutex()); |
| 2671 | ExecutionContext exe_ctx (m_opaque_sp.get()); |
| 2672 | |
| 2673 | if (log) |
| 2674 | log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr); |
| 2675 | |
| 2676 | frame = exe_ctx.GetFramePtr(); |
| 2677 | Target *target = exe_ctx.GetTargetPtr(); |
| 2678 | |
| 2679 | if (target) |
| 2680 | { |
| 2681 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2682 | StreamString frame_description; |
| 2683 | if (frame) |
| 2684 | frame->DumpUsingSettingsFormat (&frame_description); |
| 2685 | Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", |
| 2686 | expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); |
| 2687 | #endif |
| 2688 | exe_results = target->EvaluateExpression (expr, |
| 2689 | frame, |
| 2690 | expr_value_sp, |
| 2691 | options.ref()); |
| 2692 | |
| 2693 | expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); |
| 2694 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2695 | Host::SetCrashDescription (NULL); |
| 2696 | #endif |
| 2697 | } |
| 2698 | else |
| 2699 | { |
| 2700 | if (log) |
| 2701 | log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget."); |
| 2702 | } |
| 2703 | } |
| 2704 | #ifndef LLDB_DISABLE_PYTHON |
| 2705 | if (expr_log) |
| 2706 | expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **", |
| 2707 | expr_result.GetValue(), |
| 2708 | expr_result.GetSummary()); |
| 2709 | |
| 2710 | if (log) |
| 2711 | log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", |
| 2712 | frame, |
| 2713 | expr, |
| 2714 | expr_value_sp.get(), |
| 2715 | exe_results); |
| 2716 | #endif |
| 2717 | |
| 2718 | return expr_result; |
| 2719 | } |
| 2720 | |
Greg Clayton | 13fbb99 | 2013-02-01 00:47:49 +0000 | [diff] [blame] | 2721 | |
| 2722 | lldb::addr_t |
| 2723 | SBTarget::GetStackRedZoneSize() |
| 2724 | { |
| 2725 | TargetSP target_sp(GetSP()); |
| 2726 | if (target_sp) |
| 2727 | { |
| 2728 | ABISP abi_sp; |
| 2729 | ProcessSP process_sp (target_sp->GetProcessSP()); |
| 2730 | if (process_sp) |
| 2731 | abi_sp = process_sp->GetABI(); |
| 2732 | else |
| 2733 | abi_sp = ABI::FindPlugin(target_sp->GetArchitecture()); |
| 2734 | if (abi_sp) |
| 2735 | return abi_sp->GetRedZoneSize(); |
| 2736 | } |
| 2737 | return 0; |
| 2738 | } |
| 2739 | |