Firm Logo

Debug Extension

Commands

Command

dumpfilter name

only dump graphs containing the given name

init

break after initialization

create nr

break if node nr was created

replace nr

break if node nr is replaced by another node

lower nr

break before node nr is lowered

remirg nr/name

break if the irg of nr or entity name is deleted

newent nr/name

break if the entity nr or name was created

newtype nr/name

break if the type nr or name was created

bp

show all breakpoints

enable nr

enable breakpoint nr

disable nr

disable breakpoint nr

showtype nr/name

show content of type nr or name

showent nr/name

show content of entity nr or name

setmask name msk

sets the debug module to mask msk

setlvl name lvl

sets the debug module name to level lvl

setoutfile name file

redirects debug output of module name to file

irgname name

prints address and graph number of a method given by its name

irgldname name

prints address and graph number of a method given by its ldname

help

list all commands

Usage

libFirm contains a builtin debug extension helping set breakpoints and inspecting data.

Environment Variable

When firm starts up the environment variable FIRMDBG is interpreted as debug commands. Examples:

Break when node number 123 is created
$ FIRMDBG="create 123" my_firm_compiler
Enable full debug logging for the firm.be.prefalloc module
$ FIRMDBG="setmask firm.be.prefalloc -1" my_firm_compiler

Inside a debugger

The debug extension is accessed using the builtin firm_debug function.

In gdb, issue a call

call firm_debug(".help")

In the Visual Studio Debugger, simply place a call into the watch window.

Debug Functions

Further, the following functions/expression might be useful while debugging

Function

dump_ir_block_graph_sched(irg, suffix)

dumps graph irg

current_ir_graph

the current graph, set by most libFirm functions

dump_ir_block_graph(irg, suffix)

dumps graph irg

Usage in gdb macros

You can predefine gdb macros for common constructs like displaying an ir_node* or dumping the current graph for opening it in ycomp. The following is a good idea:

set unwindonsignal on

# FIRM

# The following is able to print most important firm datastructures:
# ir_node*, tarval*, ir_type*, ir_mode* and maybe others should work
define irn
print gdb_node_helper($arg0)
end

# Hack to display the length of a firm ARR_F or ARR_D
define arrlen
p array_len($arg0)
end

define dumpg
if $argc == 1
        if is_ir_graph($arg0)
                call dump_ir_graph($arg0, "XXX")
        else
        if is_ir_node($arg0)
                call dump_ir_graph(get_irn_irg($arg0), "XXX")
        else
                printf "Cannot determine graph of given argument\n"
        end
        end
else
        call dump_ir_graph(current_ir_graph, "XXX")
end
end

define firmd
call firm_debug($arg0)
end

define graph
if $argc == 1
        if is_ir_graph($arg0)
                print gdb_node_helper($arg0)
        else
        if is_ir_node($arg0)
                print gdb_node_helper(get_irn_irg($arg0))
        else
                printf "Cannot determine graph of given argument\n"
        end
        end
else
        call dump_ir_graph(current_ir_graph, "XXX")
end
end

define keep
call add_End_keepalive(get_irg_end(get_irn_irg($arg0)), $arg0)
end

# cparser
define cpexpr
call print_expression($arg0), (void)putchar('\n')
end

define cpstmt
call print_statement($arg0)
end

define cptype
call print_type($arg0), (void)putchar('\n')
end