mattreecebentley / plf_list

A drop-in replacement for std::list with 293% faster insertion, 57% faster erasure, 17% faster iteration and 77% faster sorting on average. 20-24% speed increase in use-case testing.
https://plflib.org/list.htm
zlib License
151 stars 21 forks source link

share a way to print item in plf::list in GDB #24

Closed gigglesun closed 1 year ago

gigglesun commented 1 year ago

add following to your ~/.gdbinit file:

#

define plflist
    if $argc == 0
        help plflist
    else
        set $end = $arg0.end_iterator.node_pointer
        set $current = $arg0.begin_iterator.node_pointer
        set $size = 0
        while $current != $end
            if $argc == 2
                printf "elem[%u]: ", $size
                            p *($arg1*)(&($current->element))
            end
            if $argc == 3
                if $size == $arg2
                    printf "elem[%u]: ", $size
                                    p *($arg1*)(&($current->element))
                end
            end
            set $current = $current->next
            set $size++
        end
        printf "plflist size = %u \n", $arg0.total_size
        if $argc == 1
            printf "plflist "
            whatis $arg0
            printf "Use plflist <variable_name> <element_type> to see the elements in the list.\n"
        end
    end
end

document plflist
    Prints plf::list<T> information.
    Syntax: plflist <list> <T> <idx>: Prints list size, if T defined all elements or just element at idx
    Examples:
    plflist l - prints list size and definition
    plflist l int - prints all elements and list size
    plflist l int 2 - prints the third element in the list (if exists) and list size
end

To use it in GDB:

##  plf::list<int> list1 = { 1, 2, 3, 4, 5 };

## print all items in list1
(gdb) plflist list1 int
elem[0]: $1 = 1
elem[1]: $2 = 2
elem[2]: $3 = 3
elem[3]: $4 = 4
elem[4]: $5 = 5
plflist size = 5 

## print fourth item in list1
(gdb) plflist list1 int 3
elem[3]: $6 = 4
plflist size = 5