Skip to content

Conversation

@aedart
Copy link
Contributor

@aedart aedart commented Feb 7, 2025

PR adds a new var_dump() function, which is now internally used by both dump() and dd().

Details

Consider the following example (taken from the docs):

set(my_str "Hi there")
set(my_empty_str "")
set(my_num 23)
set(my_float 1.1234)
set(my_bool true)
set(my_const on)
set(my_list "foo;bar;42;true")
set(my_cached_prop "My cached var..." CACHE STRING "Testing")
set(ENV{my_env_prop} "/home/other/place")

macro(my_macro)
endmacro()

function(my_function)
endfunction()

var_dump(PROPERTIES
    my_str
    my_empty_str
    my_num
    my_float
    my_const
    my_undefined_prop
    my_list
    my_cached_prop
    my_env_prop
    my_macro
    my_function
)

Outputs:

my_str = (string 8) "Hi there"
my_empty_str = (string 0) ""
my_num = (int) 23
my_float = (float) 1.1234
my_const = (string 2) "on"
my_undefined_prop = (undefined) 
my_list = (list 4) [ 
   0: (string 3) "foo"
   1: (string 3) "bar"
   2: (int) 42
   3: (bool) true
]
my_cached_prop = (string 4, cached) "Yolo"
my_env_prop = (string 17, ENV) "/home/other/place"
my_macro = (command) my_macro()
my_function = (command) my_function()

If ANSI is enabled, the output will be formatted / styled with colors. In addition, the var_dump() also supports a few options, which allows it to omit variable names, and treat lists as strings instead, if the default behavior isn't desirable.

@aedart aedart added the enhancement New feature or request label Feb 7, 2025
@aedart aedart requested a review from kernelguy February 7, 2025 11:58
@aedart aedart self-assigned this Feb 7, 2025
@kernelguy kernelguy merged commit 1b75a30 into main Feb 7, 2025
4 checks passed
@aedart aedart deleted the improve-debug-utils branch February 7, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants