1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 5 <link href="style.css" rel="stylesheet" type="text/css" /> 6 <title>LLDB to GDB Command Map</title> 7 </head> 8 9 <body> 10 <div class="www_title"> 11 The <strong>LLDB</strong> Debugger 12 </div> 13 14 <div id="container"> 15 <div id="content"> 16 <!--#include virtual="sidebar.incl"--> 17 <div id="middle"> 18 <div class="post"> 19 20 <h1 class ="postheader">GDB to LLDB Command Map</h1> 21 <div class="post"> 22 23 <p>Below is a table of GDB commands with the LLDB counterparts. 24 The built in GDB-compatibility aliases in LLDB are also 25 listed. The full lldb command names are often long, but any 26 unique short form can be used. Instead of "<b>breakpoint set</b>", 27 "<b>br se</b>" is also acceptable.</p> 28 </div> 29 <div class="postfooter"></div> 30 31 <h1 class ="postheader">Execution Commands</h1> 32 <div class="post"> 33 34 <p> 35 36 <table class="stats" width="620" cellspacing="0"> 37 <tr> 38 <td class="hed" width="50%">GDB</td> 39 <td class="hed" width="50%">LLDB</td> 40 </tr> 41 42 <tr><td class="header" colspan="2">Launch a process no arguments.</td></tr> 43 <td class="content"> 44 <b>(gdb)</b> run<br> 45 <b>(gdb)</b> r 46 </td> 47 <td class="content"> 48 <b>(lldb)</b> process launch<br> 49 <b>(lldb)</b> run<br> 50 <b>(lldb)</b> r 51 </td> 52 </tr> 53 54 55 <tr><td class="header" colspan="2">Launch a process with arguments <code><args></code>.</td></tr> 56 <td class="content"> 57 <b>(gdb)</b> run <args><br> 58 <b>(gdb)</b> r <args> 59 </td> 60 <td class="content"> 61 <b>(lldb)</b> process launch -- <args><br> 62 <b>(lldb)</b> r <args> 63 </td> 64 </tr> 65 66 <tr><td class="header" colspan="2">Launch a process for with arguments <b><code>a.out 1 2 3</code></b> without having to supply the args every time.</td></tr> 67 <td class="content"> 68 <b>%</b> gdb --args a.out 1 2 3<br> 69 <b>(gdb)</b> run<br> 70 ...<br> 71 <b>(gdb)</b> run<br> 72 ...<br> 73 </td> 74 <td class="content"> 75 <b>%</b> lldb -- a.out 1 2 3<br> 76 <b>(lldb)</b> run<br> 77 ...<br> 78 <b>(lldb)</b> run<br> 79 ...<br> 80 </td> 81 </tr> 82 83 <tr><td class="header" colspan="2">Or:</td></tr> 84 <td class="content"> 85 <b>(gdb)</b> set args 1 2 3<br> 86 <b>(gdb)</b> run<br> 87 ...<br> 88 <b>(gdb)</b> run<br> 89 ...<br> 90 </td> 91 <td class="content"> 92 <b>(lldb)</b> settings set target.run-args 1 2 3<br> 93 <b>(lldb)</b> run<br> 94 ...<br> 95 <b>(lldb)</b> run<br> 96 ...<br> 97 </td> 98 </tr> 99 100 <tr><td class="header" colspan="2">Launch a process with arguments in new terminal window (Mac OS X only).</td></tr> 101 <td class="content"> 102 </td> 103 <td class="content"> 104 <b>(lldb)</b> process launch --tty -- <args><br> 105 <b>(lldb)</b> pro la -t -- <args><br> 106 </td> 107 </tr> 108 109 <tr><td class="header" colspan="2">Launch a process with arguments in existing terminal <cope>/dev/ttys006</code> (Mac OS X only).</td></tr> 110 <td class="content"> 111 </td> 112 <td class="content"> 113 <b>(lldb)</b> process launch --tty=/dev/ttys006 -- <args><br> 114 <b>(lldb)</b> pro la -t/dev/ttys006 -- <args><br> 115 </td> 116 </tr> 117 118 <tr><td class="header" colspan="2">Set environment variables for process before launching.</td></tr> 119 <td class="content"> 120 <b>(gdb)</b> set env DEBUG 1<br> 121 </td> 122 <td class="content"> 123 <b>(lldb)</b> settings set target.env-vars DEBUG=1<br> 124 <b>(lldb)</b> set se target.env-vars DEBUG=1<br> 125 <b>(lldb)</b> env DEBUG=1<br> 126 </td> 127 </tr> 128 129 <tr><td class="header" colspan="2">Show the arguments that will be or were passed to the program when run.</td></tr> 130 <td class="content"> 131 <b>(gdb)</b> show args<br> 132 Argument list to give program being debugged when it is started is "1 2 3".<br> 133 </td> 134 <td class="content"> 135 <b>(lldb)</b> settings show target.run-args<br> 136 target.run-args (array of strings) =<br> 137 [0]: "1"<br> 138 [1]: "2"<br> 139 [2]: "3"<br> 140 </td> 141 </tr> 142 143 144 <tr><td class="header" colspan="2">Set environment variables for process and launch process in one command.</td></tr> 145 <td class="content"> 146 </td> 147 <td class="content"> 148 <b>(lldb)</b> process launch -v DEBUG=1<br> 149 </td> 150 </tr> 151 152 <tr><td class="header" colspan="2">Attach to a process with process ID 123.</td></tr> 153 <tr> 154 <td class="content"> 155 <b>(gdb)</b> attach 123 156 </td> 157 <td class="content"> 158 <b>(lldb)</b> process attach --pid 123<br> 159 <b>(lldb)</b> attach -p 123 160 </td> 161 </tr> 162 163 <tr><td class="header" colspan="2">Attach to a process named "a.out".</td></tr> 164 <tr> 165 <td class="content"> 166 <b>(gdb)</b> attach a.out 167 </td> 168 <td class="content"> 169 <b>(lldb)</b> process attach --name a.out<br> 170 <b>(lldb)</b> pro at -n a.out 171 </td> 172 </tr> 173 174 <tr><td class="header" colspan="2">Wait for a process named "a.out" to launch and attach.</td></tr> 175 <tr> 176 <td class="content"> 177 <b>(gdb)</b> attach -waitfor a.out 178 </td> 179 <td class="content"> 180 <b>(lldb)</b> process attach --name a.out --waitfor<br> 181 <b>(lldb)</b> pro at -n a.out -w 182 </td> 183 </tr> 184 185 <tr><td class="header" colspan="2">Attach to a remote gdb protocol server running on system "eorgadd", port 8000.</td></tr> 186 <tr> 187 <td class="content"> 188 <b>(gdb)</b> target remote eorgadd:8000 189 </td> 190 <td class="content"> 191 <b>(lldb)</b> gdb-remote eorgadd:8000 192 </td> 193 </tr> 194 195 <tr><td class="header" colspan="2">Attach to a remote gdb protocol server running on the local system, port 8000.</td></tr> 196 <tr> 197 <td class="content"> 198 <b>(gdb)</b> target remote localhost:8000 199 </td> 200 <td class="content"> 201 <b>(lldb)</b> gdb-remote 8000 202 </td> 203 </tr> 204 205 <tr><td class="header" colspan="2">Attach to a Darwin kernel in kdp mode on system "eorgadd".</td></tr> 206 <tr> 207 <td class="content"> 208 <b>(gdb)</b> kdp-reattach eorgadd 209 </td> 210 <td class="content"> 211 <b>(lldb)</b> kdp-remote eorgadd 212 </td> 213 </tr> 214 215 <tr><td class="header" colspan="2">Do a source level single step in the currently selected thread.</td></tr> 216 <tr> 217 <td class="content"> 218 <b>(gdb)</b> step<br> 219 <b>(gdb)</b> s 220 </td> 221 <td class="content"> 222 <b>(lldb)</b> thread step-in<br> 223 <b>(lldb)</b> step<br> 224 <b>(lldb)</b> s 225 </td> 226 </tr> 227 228 229 <tr><td class="header" colspan="2">Do a source level single step over in the currently selected thread.</td></tr> 230 <tr> 231 <td class="content"> 232 <b>(gdb)</b> next<br> 233 <b>(gdb)</b> n 234 </td> 235 <td class="content"> 236 <b>(lldb)</b> thread step-over<br> 237 <b>(lldb)</b> next<br> 238 <b>(lldb)</b> n<br> 239 </td> 240 </tr> 241 242 <tr><td class="header" colspan="2">Do an instruction level single step in the currently selected thread.</td></tr> 243 <tr> 244 <td class="content"> 245 <b>(gdb)</b> stepi<br> 246 <b>(gdb)</b> si 247 </td> 248 <td class="content"> 249 <b>(lldb)</b> thread step-inst<br> 250 <b>(lldb)</b> si<br> 251 </td> 252 </tr> 253 254 <tr><td class="header" colspan="2">Do an instruction level single step over in the currently selected thread.</td></tr> 255 <tr> 256 <td class="content"> 257 <b>(gdb)</b> nexti<br> 258 <b>(gdb)</b> ni 259 </td> 260 <td class="content"> 261 <b>(lldb)</b> thread step-inst-over<br> 262 <b>(lldb)</b> ni 263 </td> 264 </tr> 265 266 <tr><td class="header" colspan="2">Step out of the currently selected frame.</td></tr> 267 <tr> 268 <td class="content"> 269 <b>(gdb)</b> finish<br> 270 </td> 271 <td class="content"> 272 <b>(lldb)</b> thread step-out<br> 273 <b>(lldb)</b> finish<br> 274 </td> 275 </tr> 276 277 <tr><td class="header" colspan="2">Return immediately from the currently selected frame, with an optional return value.</td></tr> 278 <tr> 279 <td class="content"> 280 <b>(gdb)</b> return <RETURN EXPRESSION><br> 281 </td> 282 <td class="content"> 283 <b>(lldb)</b> thread return <RETURN EXPRESSION><br> 284 </td> 285 </tr> 286 287 <tr><td class="header" colspan="2">Backtrace and disassemble every time you stop.</td></tr> 288 <tr> 289 <td class="content"> 290 </td> 291 <td class="content"> 292 <b>(lldb)</b> target stop-hook add<br> 293 Enter your stop hook command(s). Type 'DONE' to end.<br> 294 > bt<br> 295 > disassemble --pc<br> 296 > DONE<br> 297 Stop hook #1 added.<br> 298 </td> 299 </tr> 300 301 </table> 302 <p> 303 </div> 304 <div class="postfooter"></div> 305 306 <h1 class ="postheader">Breakpoint Commands</h1> 307 <div class="post"> 308 309 <p> 310 311 <table class="stats" width="620" cellspacing="0"> 312 <tr> 313 <td class="hed" width="50%">GDB</td> 314 <td class="hed" width="50%">LLDB</td> 315 </tr> 316 317 <tr><td class="header" colspan="2">Set a breakpoint at all functions named <b>main</b>.</td></tr> 318 <tr> 319 <td class="content"> 320 <b>(gdb)</b> break main 321 </td> 322 <td class="content"> 323 <b>(lldb)</b> breakpoint set --name main<br> 324 <b>(lldb)</b> br s -n main<br> 325 <b>(lldb)</b> b main 326 </td> 327 </tr> 328 329 <tr><td class="header" colspan="2">Set a breakpoint in file <b>test.c</b> at line <b>12</b>.</td></tr> 330 <tr> 331 <td class="content"> 332 <b>(gdb)</b> break test.c:12 333 </td> 334 <td class="content"> 335 <b>(lldb)</b> breakpoint set --file test.c --line 12<br> 336 <b>(lldb)</b> br s -f test.c -l 12<br> 337 <b>(lldb)</b> b test.c:12 338 </td> 339 </tr> 340 341 <tr><td class="header" colspan="2">Set a breakpoint at all C++ methods whose basename is <b>main</b>.</td></tr> 342 <tr> 343 <td class="content"> 344 <b>(gdb)</b> break main<br> 345 <i>(Hope that there are no C funtions named <b>main</b>)</i>. 346 </td> 347 <td class="content"> 348 <b>(lldb)</b> breakpoint set --method main<br> 349 <b>(lldb)</b> br s -M main<br> 350 </td> 351 </tr> 352 353 <tr><td class="header" colspan="2">Set a breakpoint at and object C function: <b>-[NSString stringWithFormat:]</b>.</td></tr> 354 <tr> 355 <td class="content"> 356 <b>(gdb)</b> break -[NSString stringWithFormat:]<br> 357 </td> 358 <td class="content"> 359 <b>(lldb)</b> breakpoint set --name "-[NSString stringWithFormat:]"<br> 360 <b>(lldb)</b> b -[NSString stringWithFormat:]<br> 361 </td> 362 </tr> 363 364 <tr><td class="header" colspan="2">Set a breakpoint at all Objective C methods whose selector is <b>count</b>.</td></tr> 365 <tr> 366 <td class="content"> 367 <b>(gdb)</b> break count<br> 368 <i>(Hope that there are no C or C++ funtions named <b>count</b>)</i>. 369 </td> 370 <td class="content"> 371 <b>(lldb)</b> breakpoint set --selector count<br> 372 <b>(lldb)</b> br s -S count<br> 373 </td> 374 </tr> 375 <tr><td class="header" colspan="2">Set a breakpoint by regular expression on function name.</td></tr> 376 377 <tr> 378 <td class="content"> 379 <b>(gdb)</b> rbreak regular-expression<br> 380 </td> 381 <td class="content"> 382 <b>(lldb)</b> breakpoint set --func-regex regular-expression<br> 383 <b>(lldb)</b> br s -r regular-expression<br> 384 </td> 385 </tr> 386 387 <tr><td class="header" colspan="2">Ensure that breakpoints by file and line work for #included .c/.cpp/.m files.</td></tr> 388 389 <tr> 390 <td class="content"> 391 <b>(gdb)</b> b foo.c:12<br> 392 </td> 393 <td class="content"> 394 <b>(lldb)</b> settings set target.inline-breakpoint-strategy always<br> 395 <b>(lldb)</b> br s -f foo.c -l 12<br> 396 </td> 397 </tr> 398 399 <tr><td class="header" colspan="2">Set a breakpoint by regular expression on source file contents.</td></tr> 400 401 <tr> 402 <td class="content"> 403 <b>(gdb)</b> shell grep -e -n pattern source-file<br> 404 <b>(gdb)</b> break source-file:CopyLineNumbers<br> 405 </td> 406 <td class="content"> 407 <b>(lldb)</b> breakpoint set --source-pattern regular-expression --file SourceFile<br> 408 <b>(lldb)</b> br s -p regular-expression -f file<br> 409 </td> 410 </tr> 411 412 <tr><td class="header" colspan="2">List all breakpoints.</td></tr> 413 <tr> 414 <td class="content"> 415 <b>(gdb)</b> info break<br> 416 </td> 417 <td class="content"> 418 <b>(lldb)</b> breakpoint list<br> 419 <b>(lldb)</b> br l<br> 420 </td> 421 </tr> 422 423 <tr><td class="header" colspan="2">Delete a breakpoint.</td></tr> 424 <tr> 425 <td class="content"> 426 <b>(gdb)</b> delete 1<br> 427 </td> 428 <td class="content"> 429 <b>(lldb)</b> breakpoint delete 1<br> 430 <b>(lldb)</b> br del 1<br> 431 </td> 432 </tr> 433 434 </table> 435 <p> 436 </div> 437 <div class="postfooter"></div> 438 439 <h1 class ="postheader">Watchpoint Commands</h1> 440 <div class="post"> 441 442 <p> 443 444 <table class="stats" width="620" cellspacing="0"> 445 <tr> 446 <td class="hed" width="50%">GDB</td> 447 <td class="hed" width="50%">LLDB</td> 448 </tr> 449 450 <tr><td class="header" colspan="2">Set a watchpoint on a variable when it is written to.</td></tr> 451 <tr> 452 <td class="content"> 453 <b>(gdb)</b> watch global_var 454 </td> 455 <td class="content"> 456 <b>(lldb)</b> watchpoint set variable global_var<br> 457 <b>(lldb)</b> wa s v global_var<br> 458 </td> 459 </tr> 460 461 <tr><td class="header" colspan="2">Set a watchpoint on a memory location when it is written into. The size of the region to watch for defaults to the pointer size if no '-x byte_size' is specified. 462 This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the '--' option terminator.</td></tr> 463 <tr> 464 <td class="content"> 465 <b>(gdb)</b> watch -location g_char_ptr 466 </td> 467 <td class="content"> 468 <b>(lldb)</b> watchpoint set expression -- my_ptr<br> 469 <b>(lldb)</b> wa s e -- my_ptr<br> 470 </td> 471 </tr> 472 473 <tr><td class="header" colspan="2">Set a condition on a watchpoint</b>.</td></tr> 474 <tr> 475 <td class="content"> 476 </td> 477 <td class="content"> 478 <b>(lldb)</b> watch set var global<br> 479 <b>(lldb)</b> watchpoint modify -c '(global==5)'<br> 480 <b>(lldb)</b> c<br> 481 ...<br> 482 <b>(lldb)</b> bt<br> 483 * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1<br> 484 frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16<br> 485 frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25<br> 486 frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1<br> 487 <b>(lldb)</b> frame var global<br> 488 (int32_t) global = 5<br> 489 </td> 490 </tr> 491 492 <tr><td class="header" colspan="2">List all watchpoints.</td></tr> 493 <tr> 494 <td class="content"> 495 <b>(gdb)</b> info break<br> 496 </td> 497 <td class="content"> 498 <b>(lldb)</b> watchpoint list<br> 499 <b>(lldb)</b> watch l<br> 500 </td> 501 </tr> 502 503 <tr><td class="header" colspan="2">Delete a watchpoint.</td></tr> 504 <tr> 505 <td class="content"> 506 <b>(gdb)</b> delete 1<br> 507 </td> 508 <td class="content"> 509 <b>(lldb)</b> watchpoint delete 1<br> 510 <b>(lldb)</b> watch del 1<br> 511 </td> 512 </tr> 513 514 </table> 515 <p> 516 </div> 517 518 <div class="postfooter"></div> 519 <h1 class ="postheader">Examining Variables</h1> 520 <div class="post"> 521 <p> 522 <table class="stats" width="620" cellspacing="0"> 523 <tr> 524 <td class="hed" width="50%">GDB</td> 525 <td class="hed" width="50%">LLDB</td> 526 </tr> 527 528 <tr><td class="header" colspan="2">Show the arguments and local variables for the current frame.</td></tr> 529 <tr> 530 <td class="content"> 531 <b>(gdb)</b> info args<br> 532 and<br> 533 <b>(gdb)</b> info locals<br> 534 </td> 535 <td class="content"> 536 <b>(lldb)</b> frame variable<br> 537 <b>(lldb)</b> fr v<br> 538 </td> 539 </tr> 540 541 <tr><td class="header" colspan="2">Show the local variables for the current frame.</td></tr> 542 <tr> 543 <td class="content"> 544 <b>(gdb)</b> info locals<br> 545 </td> 546 <td class="content"> 547 <b>(lldb)</b> frame variable --no-args<br> 548 <b>(lldb)</b> fr v -a<br> 549 </td> 550 </tr> 551 552 <tr><td class="header" colspan="2">Show the contents of local variable "bar".</td></tr> 553 <tr> 554 <td class="content"> 555 <b>(gdb)</b> p bar<br> 556 </td> 557 <td class="content"> 558 <b>(lldb)</b> frame variable bar <br> 559 <b>(lldb)</b> fr v bar <br> 560 <b>(lldb)</b> p bar <br> 561 </td> 562 </tr> 563 564 <tr><td class="header" colspan="2">Show the contents of local variable "bar" formatted as hex.</td></tr> 565 <tr> 566 <td class="content"> 567 <b>(gdb)</b> p/x bar<br> 568 </td> 569 <td class="content"> 570 <b>(lldb)</b> frame variable --format x bar <br> 571 <b>(lldb)</b> fr v -f x bar <br> 572 </td> 573 </tr> 574 575 <tr><td class="header" colspan="2">Show the contents of global variable "baz".</td></tr> 576 <tr> 577 <td class="content"> 578 <b>(gdb)</b> p baz<br> 579 </td> 580 <td class="content"> 581 <b>(lldb)</b> target variable baz <br> 582 <b>(lldb)</b> ta v baz <br> 583 </td> 584 </tr> 585 586 <tr><td class="header" colspan="2">Show the global/static variables defined in the current source file.</td></tr> 587 <tr> 588 <td class="content"> 589 n/a<br> 590 </td> 591 <td class="content"> 592 <b>(lldb)</b> target variable <br> 593 <b>(lldb)</b> ta v <br> 594 </td> 595 </tr> 596 597 <tr><td class="header" colspan="2">Display a the variable "argc" and "argv" every time you stop.</td></tr> 598 <tr> 599 <td class="content"> 600 <b>(gdb)</b> display argc<br> 601 <b>(gdb)</b> display argv<br> 602 </td> 603 <td class="content"> 604 <b>(lldb)</b> target stop-hook add --one-liner "frame variable argc argv"<br> 605 <b>(lldb)</b> ta st a -o "fr v argc argv"<br> 606 <b>(lldb)</b> display argc<br> 607 <b>(lldb)</b> display argv<br> 608 </td> 609 </tr> 610 611 <tr><td class="header" colspan="2">Display a the variable "argc" and "argv" only when you stop in the function named <b>main</b>.</td></tr> 612 <tr> 613 <td class="content"> 614 </td> 615 <td class="content"> 616 <b>(lldb)</b> target stop-hook add --name main --one-liner "frame variable argc argv"<br> 617 <b>(lldb)</b> ta st a -n main -o "fr v argc argv"<br> 618 </td> 619 </tr> 620 621 <tr><td class="header" colspan="2">Display the variable "*this" only when you stop in c class named <b>MyClass</b>.</td></tr> 622 <tr> 623 <td class="content"> 624 </td> 625 <td class="content"> 626 <b>(lldb)</b> target stop-hook add --classname MyClass --one-liner "frame variable *this"<br> 627 <b>(lldb)</b> ta st a -c MyClass -o "fr v *this"<br> 628 </td> 629 </tr> 630 631 </table> 632 <p> 633 </div> 634 635 636 637 638 <h1 class ="postheader">Evaluating expressions</h1> 639 <div class="post"> 640 <p> 641 <table class="stats" width="620" cellspacing="0"> 642 <tr> 643 <td class="hed" width="50%">GDB</td> 644 <td class="hed" width="50%">LLDB</td> 645 </tr> 646 647 <tr><td class="header" colspan="2">Evaluating a generalized expression in the current frame.</td></tr> 648 <tr> 649 <td class="content"> 650 <b>(gdb)</b> print (int) printf ("Print nine: %d.", 4 + 5)<br> 651 or if you don't want to see void returns: <br> 652 <b>(gdb)</b> call (int) printf ("Print nine: %d.", 4 + 5)<br> 653 </td> 654 <td class="content"> 655 <b>(lldb)</b> expr (int) printf ("Print nine: %d.", 4 + 5)<br> 656 or using the print alias:<br> 657 <b>(lldb)</b> print (int) printf ("Print nine: %d.", 4 + 5)<br> 658 </td> 659 </tr> 660 661 <tr><td class="header" colspan="2">Creating and assigning a value to a convenience variable.</td></tr> 662 <tr> 663 <td class="content"> 664 <b>(gdb)</b> set $foo = 5<br> 665 <b>(gdb)</b> set variable $foo = 5<br> 666 or using the print command <br> 667 <b>(gdb)</b> print $foo = 5<br> 668 or using the call command <br> 669 <b>(gdb)</b> call $foo = 5<br> 670 and if you want to specify the type of the variable: 671 <b>(gdb)</b> set $foo = (unsigned int) 5<br> 672 673 </td> 674 <td class="content"> 675 In lldb you evaluate a variable declaration expression as you would write it in C:<br> 676 <b>(lldb)</b> expr unsigned int $foo = 5<br> 677 </td> 678 </tr> 679 680 <tr><td class="header" colspan="2">Printing the ObjC "description" of an object.</td></tr> 681 <tr> 682 <td class="content"> 683 <b>(gdb)</b> po [SomeClass returnAnObject]<br> 684 </td> 685 <td class="content"> 686 <b>(lldb)</b> expr -o -- [SomeClass returnAnObject]<br> 687 or using the po alias:<br> 688 <b>(lldb)</b> po [SomeClass returnAnObject]<br> 689 </td> 690 </tr> 691 692 <tr><td class="header" colspan="2">Print the dynamic type of the result of an expression.</td></tr> 693 <tr> 694 <td class="content"> 695 <b>(gdb)</b> set print object 1<br> 696 <b>(gdb)</b> p someCPPObjectPtrOrReference<br> 697 only works for C++ objects.<br> 698 </td> 699 <td class="content"> 700 <b>(lldb)</b> expr -d 1 -- [SomeClass returnAnObject]<br> 701 <b>(lldb)</b> expr -d 1 -- someCPPObjectPtrOrReference<br> 702 or set dynamic type printing to be the default: 703 <b>(lldb)</b> settings set target.prefer-dynamic run-target<br> 704 </td> 705 </tr> 706 707 <tr><td class="header" colspan="2">Calling a function so you can stop at a breakpoint in the function.</td></tr> 708 <tr> 709 <td class="content"> 710 <b>(gdb)</b> set unwindonsignal 0<br> 711 <b>(gdb)</b> p function_with_a_breakpoint()<br> 712 </td> 713 <td class="content"> 714 <b>(lldb)</b> expr -i 0 -- function_with_a_breakpoint()<br> 715 </td> 716 </tr> 717 718 <tr><td class="header" colspan="2">Calling a function that crashes, and stopping when the function crashes.</td></tr> 719 <tr> 720 <td class="content"> 721 <b>(gdb)</b> set unwindonsignal 0<br> 722 <b>(gdb)</b> p function_which_crashes()<br> 723 </td> 724 <td class="content"> 725 <b>(lldb)</b> expr -u 0 -- function_which_crashes()<br> 726 </td> 727 </tr> 728 729 730 </table> 731 <p> 732 </div> 733 734 <h1 class ="postheader">Examining Thread State</h1> 735 <div class="post"> 736 <p> 737 <table class="stats" width="620" cellspacing="0"> 738 <tr> 739 <td class="hed" width="50%">GDB</td> 740 <td class="hed" width="50%">LLDB</td> 741 </tr> 742 743 744 <tr><td class="header" colspan="2">Show the stack backtrace for the current thread.</td></tr> 745 <tr> 746 <td class="content"> 747 <b>(gdb)</b> bt<br> 748 </td> 749 <td class="content"> 750 <b>(lldb)</b> thread backtrace<br> 751 <b>(lldb)</b> bt<br> 752 </td> 753 </tr> 754 755 <tr><td class="header" colspan="2">Show the stack backtraces for all threads.</td></tr> 756 <tr> 757 <td class="content"> 758 <b>(gdb)</b> thread apply all bt 759 </td> 760 <td class="content"> 761 <b>(lldb)</b> thread backtrace all<br> 762 <b>(lldb)</b> bt all 763 </td> 764 </tr> 765 766 <tr><td class="header" colspan="2">Backtrace the first five frames of the current thread.</td></tr> 767 <tr> 768 <td class="content"> 769 <b>(gdb)</b> bt 5 770 </td> 771 <td class="content"> 772 <b>(lldb)</b> thread backtrace -c 5<br> 773 <b>(lldb)</b> bt 5 (<i>lldb-169 and later</i>)<br> 774 <b>(lldb)</b> bt -c 5 (<i>lldb-168 and earlier</i>) 775 </td> 776 </tr> 777 778 <tr><td class="header" colspan="2">Select a different stack frame by index for the current thread.</td></tr> 779 <tr> 780 <td class="content"> 781 <b>(gdb)</b> frame 12 782 </td> 783 <td class="content"> 784 <b>(lldb)</b> frame select 12<br> 785 <b>(lldb)</b> fr s 12<br> 786 <b>(lldb)</b> f 12<br> 787 </td> 788 </tr> 789 790 <tr><td class="header" colspan="2">List information about the currently selected frame in the current thread.</td></tr> 791 <tr> 792 <td class="content"> 793 </td> 794 <td class="content"> 795 <b>(lldb)</b> frame info<br> 796 </td> 797 </tr> 798 799 <tr><td class="header" colspan="2">Select the stack frame that called the current stack frame.</td></tr> 800 <tr> 801 <td class="content"> 802 <b>(gdb)</b> up 803 </td> 804 <td class="content"> 805 <b>(lldb)</b> up<br> 806 <b>(lldb)</b> frame select --relative=1<br> 807 </td> 808 </tr> 809 810 <tr><td class="header" colspan="2">Select the stack frame that is called by the current stack frame.</td></tr> 811 <tr> 812 <td class="content"> 813 <b>(gdb)</b> down 814 </td> 815 <td class="content"> 816 <b>(lldb)</b> down<br> 817 <b>(lldb)</b> frame select --relative=-1<br> 818 <b>(lldb)</b> fr s -r-1<br> 819 </td> 820 </tr> 821 822 <tr><td class="header" colspan="2">Select a different stack frame using a relative offset.</td></tr> 823 <tr> 824 <td class="content"> 825 <b>(gdb)</b> up 2<br> 826 <b>(gdb)</b> down 3<br> 827 </td> 828 <td class="content"> 829 <b>(lldb)</b> frame select --relative 2<br> 830 <b>(lldb)</b> fr s -r2<br> 831 <br> 832 <b>(lldb)</b> frame select --relative -3<br> 833 <b>(lldb)</b> fr s -r-3<br> 834 </td> 835 </tr> 836 837 <tr><td class="header" colspan="2">Show the general purpose registers for the current thread.</td></tr> 838 <tr> 839 <td class="content"> 840 <b>(gdb)</b> info registers<br> 841 </td> 842 <td class="content"> 843 <b>(lldb)</b> register read<br> 844 </td> 845 </tr> 846 847 <tr><td class="header" colspan="2">Write a new decimal value '123' to the current thread register 'rax'.</td></tr> 848 <tr> 849 <td class="content"> 850 <b>(gdb)</b> p $rax = 123<br> 851 </td> 852 <td class="content"> 853 <b>(lldb)</b> register write rax 123<br> 854 </td> 855 </tr> 856 857 <tr><td class="header" colspan="2">Skip 8 bytes ahead of the current program counter (instruction pointer). Note that we use backticks to evaluate an expression and insert the scalar result in LLDB.</td></tr> 858 <tr> 859 <td class="content"> 860 <b>(gdb)</b> jump *$pc+8<br> 861 </td> 862 <td class="content"> 863 <b>(lldb)</b> register write pc `$pc+8`<br> 864 </td> 865 </tr> 866 867 <tr><td class="header" colspan="2">Show the general purpose registers for the current thread formatted as <b>signed decimal</b>. LLDB tries to use 868 the same format characters as <b>printf(3)</b> when possible. Type "help format" to see the full list of format specifiers.</td></tr> 869 <tr> 870 <td class="content"> 871 </td> 872 <td class="content"> 873 <b>(lldb)</b> register read --format i<br> 874 <b>(lldb)</b> re r -f i<br> 875 <br> 876 <i>LLDB now supports the GDB shorthand format syntax but there can't be space after the command:</i><br> 877 <b>(lldb)</b> register read/d<br> 878 </td> 879 </tr> 880 881 <tr><td class="header" colspan="2">Show all registers in all register sets for the current thread.</td></tr> 882 <tr> 883 <td class="content"> 884 <b>(gdb)</b> info all-registers<br> 885 </td> 886 <td class="content"> 887 <b>(lldb)</b> register read --all<br> 888 <b>(lldb)</b> re r -a<br> 889 </td> 890 </tr> 891 892 <tr><td class="header" colspan="2">Show the values for the registers named "rax", "rsp" and "rbp" in the current thread.</td></tr> 893 <tr> 894 <td class="content"> 895 <b>(gdb)</b> info all-registers rax rsp rbp<br> 896 </td> 897 <td class="content"> 898 <b>(lldb)</b> register read rax rsp rbp<br> 899 </td> 900 </tr> 901 902 <tr><td class="header" colspan="2">Show the values for the register named "rax" in the current thread formatted as <b>binary</b>.</td></tr> 903 <tr> 904 <td class="content"> 905 <b>(gdb)</b> p/t $rax<br> 906 </td> 907 <td class="content"> 908 <b>(lldb)</b> register read --format binary rax<br> 909 <b>(lldb)</b> re r -f b rax<br> 910 <br> 911 <i>LLDB now supports the GDB shorthand format syntax but there can't be space after the command:</i><br> 912 <b>(lldb)</b> register read/t rax<br> 913 <b>(lldb)</b> p/t $rax<br> 914 </td> 915 </tr> 916 917 <tr><td class="header" colspan="2">Read memory from address 0xbffff3c0 and show 4 hex uint32_t values.</td></tr> 918 <tr> 919 <td class="content"> 920 <b>(gdb)</b> x/4xw 0xbffff3c0<br> 921 </td> 922 <td class="content"> 923 <b>(lldb)</b> memory read --size 4 --format x --count 4 0xbffff3c0<br> 924 <b>(lldb)</b> me r -s4 -fx -c4 0xbffff3c0<br> 925 <b>(lldb)</b> x -s4 -fx -c4 0xbffff3c0<br> 926 <br> 927 <i>LLDB now supports the GDB shorthand format syntax but there can't be space after the command:</i><br> 928 <b>(lldb)</b> memory read/4xw 0xbffff3c0<br> 929 <b>(lldb)</b> x/4xw 0xbffff3c0<br> 930 <b>(lldb)</b> memory read --gdb-format 4xw 0xbffff3c0<br> 931 </td> 932 </tr> 933 934 <tr><td class="header" colspan="2">Read memory starting at the expression "argv[0]".</td></tr> 935 <tr> 936 <td class="content"> 937 <b>(gdb)</b> x argv[0]<br> 938 </td> 939 <td class="content"> 940 <b>(lldb)</b> memory read `argv[0]`<br> 941 <i><b>NOTE:</b> any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:</i><br> 942 <b>(lldb)</b> memory read --size `sizeof(int)` `argv[0]`<br> 943 </td> 944 </tr> 945 946 <tr><td class="header" colspan="2">Read 512 bytes of memory from address 0xbffff3c0 and save results to a local file as <b>text</b>.</td></tr> 947 <tr> 948 <td class="content"> 949 <b>(gdb)</b> set logging on<br> 950 <b>(gdb)</b> set logging file /tmp/mem.txt<br> 951 <b>(gdb)</b> x/512bx 0xbffff3c0<br> 952 <b>(gdb)</b> set logging off<br> 953 </td> 954 <td class="content"> 955 <b>(lldb)</b> memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0<br> 956 <b>(lldb)</b> me r -o/tmp/mem.txt -c512 0xbffff3c0<br> 957 <b>(lldb)</b> x/512bx -o/tmp/mem.txt 0xbffff3c0<br> 958 </td> 959 </tr> 960 961 <tr><td class="header" colspan="2">Save binary memory data starting at 0x1000 and ending at 0x2000 to a file.</td></tr> 962 <tr> 963 <td class="content"> 964 <b>(gdb)</b> dump memory /tmp/mem.bin 0x1000 0x2000 965 </td> 966 <td class="content"> 967 <b>(lldb)</b> memory read --outfile /tmp/mem.bin --binary 0x1000 0x1200<br> 968 <b>(lldb)</b> me r -o /tmp/mem.bin -b 0x1000 0x1200<br> 969 </td> 970 </tr> 971 <tr><td class="header" colspan="2">Get information about a specific heap allocation (available on Mac OS X only).</td></tr> 972 <tr> 973 <td class="content"> 974 <b>(gdb)</b> info malloc 0x10010d680 975 </td> 976 <td class="content"> 977 <b>(lldb)</b> command script import lldb.macosx.heap<br> 978 <b>(lldb)</b> process launch --environment MallocStackLogging=1 -- [ARGS]<br> 979 <b>(lldb)</b> malloc_info --stack-history 0x10010d680<br> 980 </td> 981 </tr> 982 <tr><td class="header" colspan="2">Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (available on Mac OS X only)</td></tr> 983 <tr> 984 <td class="content"> 985 </td> 986 <td class="content"> 987 <b>(lldb)</b> command script import lldb.macosx.heap<br> 988 <b>(lldb)</b> malloc_info --type 0x10010d680<br> 989 </td> 990 </tr> 991 <tr><td class="header" colspan="2">Find all heap blocks that contain a pointer specified by an expression EXPR (available on Mac OS X only).</td></tr> 992 <tr> 993 <td class="content"> 994 </td> 995 <td class="content"> 996 <b>(lldb)</b> command script import lldb.macosx.heap<br> 997 <b>(lldb)</b> ptr_refs EXPR <br> 998 </td> 999 </tr> 1000 <tr><td class="header" colspan="2">Find all heap blocks that contain a C string anywhere in the block (available on Mac OS X only).</td></tr> 1001 <tr> 1002 <td class="content"> 1003 </td> 1004 <td class="content"> 1005 <b>(lldb)</b> command script import lldb.macosx.heap<br> 1006 <b>(lldb)</b> cstr_refs CSTRING<br> 1007 </td> 1008 </tr> 1009 <tr><td class="header" colspan="2">Disassemble the current function for the current frame.</td></tr> 1010 <tr> 1011 <td class="content"> 1012 <b>(gdb)</b> disassemble 1013 </td> 1014 <td class="content"> 1015 <b>(lldb)</b> disassemble --frame<br> 1016 <b>(lldb)</b> di -f 1017 </td> 1018 </tr> 1019 1020 <tr><td class="header" colspan="2">Disassemble any functions named <b>main</b>.</td></tr> 1021 <tr> 1022 <td class="content"> 1023 <b>(gdb)</b> disassemble main 1024 </td> 1025 <td class="content"> 1026 <b>(lldb)</b> disassemble --name main<br> 1027 <b>(lldb)</b> di -n main 1028 </td> 1029 </tr> 1030 1031 <tr><td class="header" colspan="2">Disassemble an address range.</td></tr> 1032 <tr> 1033 <td class="content"> 1034 <b>(gdb)</b> disassemble 0x1eb8 0x1ec3 1035 </td> 1036 <td class="content"> 1037 <b>(lldb)</b> disassemble --start-address 0x1eb8 --end-address 0x1ec3<br> 1038 <b>(lldb)</b> di -s 0x1eb8 -e 0x1ec3<br> 1039 </td> 1040 </tr> 1041 1042 <tr><td class="header" colspan="2">Disassemble 20 instructions from a given address.</td></tr> 1043 <tr> 1044 <td class="content"> 1045 <b>(gdb)</b> x/20i 0x1eb8 1046 </td> 1047 <td class="content"> 1048 <b>(lldb)</b> disassemble --start-address 0x1eb8 --count 20<br> 1049 <b>(lldb)</b> di -s 0x1eb8 -c 20<br> 1050 </td> 1051 </tr> 1052 1053 <tr><td class="header" colspan="2">Show mixed source and disassembly for the current function for the current frame.</td></tr> 1054 <tr> 1055 <td class="content"> 1056 n/a 1057 </td> 1058 <td class="content"> 1059 <b>(lldb)</b> disassemble --frame --mixed<br> 1060 <b>(lldb)</b> di -f -m 1061 </td> 1062 </tr> 1063 1064 <tr><td class="header" colspan="2">Disassemble the current function for the current frame and show the opcode bytes.</td></tr> 1065 <tr> 1066 <td class="content"> 1067 n/a 1068 </td> 1069 <td class="content"> 1070 <b>(lldb)</b> disassemble --frame --bytes<br> 1071 <b>(lldb)</b> di -f -b 1072 </td> 1073 </tr> 1074 1075 <tr><td class="header" colspan="2">Disassemble the current source line for the current frame.</td></tr> 1076 <tr> 1077 <td class="content"> 1078 n/a 1079 </td> 1080 <td class="content"> 1081 <b>(lldb)</b> disassemble --line<br> 1082 <b>(lldb)</b> di -l 1083 </td> 1084 </tr> 1085 1086 </table> 1087 <p> 1088 </div> 1089 <div class="postfooter"></div> 1090 1091 <h1 class ="postheader">Executable and Shared Library Query Commands</h1> 1092 <div class="post"> 1093 1094 <p> 1095 1096 <table class="stats" width="620" cellspacing="0"> 1097 <tr> 1098 <td class="hed" width="50%">GDB</td> 1099 <td class="hed" width="50%">LLDB</td> 1100 </tr> 1101 1102 1103 <tr><td class="header" colspan="2">List the main executable and all dependent shared libraries.</td></tr> 1104 <tr> 1105 <td class="content"> 1106 <b>(gdb)</b> info shared<br> 1107 </td> 1108 <td class="content"> 1109 <b>(lldb)</b> image list<br> 1110 </td> 1111 </tr> 1112 1113 <tr><td class="header" colspan="2">Look up information for a raw address in the executable or any shared libraries.</td></tr> 1114 <tr> 1115 <td class="content"> 1116 <b>(gdb)</b> info symbol 0x1ec4<br> 1117 </td> 1118 <td class="content"> 1119 <b>(lldb)</b> image lookup --address 0x1ec4<br> 1120 <b>(lldb)</b> im loo -a 0x1ec4<br> 1121 </td> 1122 </tr> 1123 1124 <tr><td class="header" colspan="2">Look up functions matching a regular expression in a binary.</td></tr> 1125 <tr> 1126 <td class="content"> 1127 <b>(gdb)</b> info function <FUNC_REGEX><br> 1128 </td> 1129 <td class="content"> 1130 This one finds debug symbols:<br> 1131 <b>(lldb)</b> image lookup -r -n <FUNC_REGEX><br><br> 1132 This one finds non-debug symbols:<br> 1133 <b>(lldb)</b> image lookup -r -s <FUNC_REGEX><br><br> 1134 Provide a list of binaries as arguments to limit the search. 1135 </td> 1136 </tr> 1137 1138 <tr><td class="header" colspan="2">Find full souce line information.</td></tr> 1139 <tr> 1140 <td class="content"> 1141 <b>(gdb)</b> info line 0x1ec4<br> 1142 </td> 1143 <td class="content"> 1144 This one is a bit messy at present. Do:<br><br> 1145 <b>(lldb)</b> image lookup -v --address 0x1ec4<br><br> 1146 and look for the LineEntry line, which will have the full source path and 1147 line range information.<br> 1148 </td> 1149 </tr> 1150 1151 <tr><td class="header" colspan="2">Look up information for an address in <b>a.out</b> only.</td></tr> 1152 <tr> 1153 <td class="content"> 1154 </td> 1155 <td class="content"> 1156 <b>(lldb)</b> image lookup --address 0x1ec4 a.out<br> 1157 <b>(lldb)</b> im loo -a 0x1ec4 a.out<br> 1158 </td> 1159 </tr> 1160 1161 <tr><td class="header" colspan="2">Look up information for for a type <code>Point</code> by name.</td></tr> 1162 <tr> 1163 <td class="content"> 1164 <b>(gdb)</b> ptype Point<br> 1165 </td> 1166 <td class="content"> 1167 <b>(lldb)</b> image lookup --type Point<br> 1168 <b>(lldb)</b> im loo -t Point<br> 1169 </td> 1170 </tr> 1171 1172 <tr><td class="header" colspan="2">Dump all sections from the main executable and any shared libraries.</td></tr> 1173 <tr> 1174 <td class="content"> 1175 <b>(gdb)</b> maintenance info sections<br> 1176 </td> 1177 <td class="content"> 1178 <b>(lldb)</b> image dump sections<br> 1179 </td> 1180 </tr> 1181 1182 <tr><td class="header" colspan="2">Dump all sections in the <b>a.out</b> module.</td></tr> 1183 <tr> 1184 <td class="content"> 1185 </td> 1186 <td class="content"> 1187 <b>(lldb)</b> image dump sections a.out<br> 1188 </td> 1189 </tr> 1190 1191 <tr><td class="header" colspan="2">Dump all symbols from the main executable and any shared libraries.</td></tr> 1192 <tr> 1193 <td class="content"> 1194 </td> 1195 <td class="content"> 1196 <b>(lldb)</b> image dump symtab<br> 1197 </td> 1198 </tr> 1199 1200 <tr><td class="header" colspan="2">Dump all symbols in <b>a.out</b> and <b>liba.so</b>.</td></tr> 1201 <tr> 1202 <td class="content"> 1203 </td> 1204 <td class="content"> 1205 <b>(lldb)</b> image dump symtab a.out liba.so<br> 1206 </td> 1207 </tr> 1208 1209 </table> 1210 <p> 1211 </div> 1212 <div class="postfooter"></div> 1213 <h1 class ="postheader">Miscellaneous</h1> 1214 <div class="post"> 1215 <p> 1216 <table class="stats" width="620" cellspacing="0"> 1217 <tr> 1218 <td class="hed" width="50%">GDB</td> 1219 <td class="hed" width="50%">LLDB</td> 1220 </tr> 1221 1222 <tr><td class="header" colspan="2">Echo text to the screen.</td></tr> 1223 <tr> 1224 <td class="content"> 1225 <b>(gdb)</b> echo Here is some text\n<br> 1226 </td> 1227 <td class="content"> 1228 <b>(lldb)</b> script print "Here is some text"<br> 1229 </td> 1230 </tr> 1231 1232 <tr><td class="header" colspan="2">Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built --- maybe the program was built on a different computer --- you need to tell the debugger how to find the sources at their local file path instead of the build system's file path.</td></tr> 1233 <tr> 1234 <td class="content"> 1235 <b>(gdb)</b> set pathname-substitutions /buildbot/path /my/path<br> 1236 </td> 1237 <td class="content"> 1238 <b>(lldb)</b> settings set target.source-map /buildbot/path /my/path<br> 1239 </td> 1240 </tr> 1241 1242 <tr><td class="header" colspan="2">Supply a catchall directory to search for source files in.</td></tr> 1243 <tr> 1244 <td class="content"> 1245 <b>(gdb)</b> directory /my/path<br> 1246 </td> 1247 <td class="content"> 1248 (<i>No equivalent command - use the source-map instead.)<br> 1249 </td> 1250 </tr> 1251 1252 </table> 1253 <p> 1254 </div> 1255 1256 <div class="postfooter"></div> 1257 1258 <p> 1259 1260 1261 </div> 1262 </div> 1263 </div> 1264 </div> 1265 </body> 1266 </html> 1267