Viewing a dynamically-allocated array with the Xcode debugger?

后端 未结 4 1754
自闭症患者
自闭症患者 2020-12-23 14:59

Let\'s say I have an array in C++:

double* velocity = new double[100];

Using the GDB command line, I can view this array with the command:<

相关标签:
4条回答
  • 2020-12-23 15:21

    As of Xcode 10, you can right-click velocity, choose "View value as..." and then "Custom Type". Then cast it to (double(&)[100]) *velocity and display the array in the GUI.

    0 讨论(0)
  • 2020-12-23 15:25

    You can use gdb syntax as expressions:

    1. Use Run/Show/Expressions... menu to show the expressions window
    2. Enter '*velocity @ 100' at the bottom of the window (Expression:)
    0 讨论(0)
  • 2020-12-23 15:25

    I think that my answer will be a good addition for the old one.

    New versions of Xcode use lldb debugger as default tool instead of gdb.

    According this page:

    With the release of Xcode 5, the LLDB debugger becomes the foundation for the debugging experience on OS X.

    So for Xcode since version 5 and up I use this lldb command:

    memory read -t int -c8 `array_name`
    

    where:
    8 - the number of elements in array
    array_name - the name of array
    int - the type of array

    The result of execution of this command will be something like this:

    (lldb) memory read -t int -c8 array
    (int) 0x7fff5fbff870 = 7
    (int) 0x7fff5fbff874 = 6
    (int) 0x7fff5fbff878 = 9
    (int) 0x7fff5fbff87c = 10
    (int) 0x7fff5fbff880 = 1
    (int) 0x7fff5fbff884 = 8
    (int) 0x7fff5fbff888 = 4
    (int) 0x7fff5fbff88c = 3
    

    0 讨论(0)
  • 2020-12-23 15:30

    No unfortunately the GUI is limited and you will need to blend in a good mix of GDB magic to get things done.

    0 讨论(0)
提交回复
热议问题