File: gdb_grub.in

package info (click to toggle)
grub2 2.14~git20250718.0e36779-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 60,688 kB
  • sloc: ansic: 541,811; asm: 68,074; sh: 9,803; cpp: 2,095; makefile: 1,895; python: 1,518; sed: 446; lex: 393; yacc: 268; awk: 85; lisp: 54; perl: 31
file content (136 lines) | stat: -rw-r--r-- 3,536 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
###
### Load debuging information about GNU GRUB 2 modules into GDB
### automatically. Needs readelf, objdump, Python and gdb_helper.py script
###
### Has to be launched from the writable and trusted
### directory containing *.image and *.module
###
### $Id: .gdbinit,v 1.1 2006/05/14 11:38:08 lkundrak Exp $
### Lubomir Kundrak <lkudrak@skosi.org>
###

source gdb_helper.py


define dynamic_load_symbols
	dynamic_load_kernel_exec_symbols $arg0

	run_on_start

	# We may have been very late to loading the kernel.exec symbols and
	# and modules may already be loaded. So load symbols for any already
	# loaded.
	load_all_modules

	if $is_grub_loaded()
		runtime_load_module
	end
end
document dynamic_load_symbols
	Load debugging symbols from kernel.exec and any loaded modules given
	the address of the .text segment of the UEFI binary in memory. Also
	setup session to automatically load module symbols for modules loaded
	in the future.
end

define load_all_modules
	set $this = grub_dl_head
	while ($this != 0)
		load_module $this
		set $this = $this->next
	end
end
document load_all_modules
	Load debugging information for all loaded modules.
end

define runtime_load_module
	break grub_dl_add
	commands
		silent
		load_module mod
		cont
	end
end
document runtime_load_module
	Load module symbols at runtime as they are loaded.
end

define run_on_start
	# TODO: Add check to see if _start symbol is defined, if not, then
	# the symbols have not yet been loaded and this command will not work.
	watch *_start
	set $break_efi_start_bpnum = $bpnum
	commands
		silent
		delete $break_efi_start_bpnum

		# Save the breakpoints here before the GRUB image is loaded
		# into memory, then delete them. Later they will be reloaded
		# once the GRUB image has been loaded. This avoids the issue
		# where the loading of the GRUB image overwrites the software
		# breakpoints, thus confusing GDB and effectively clearing
		# those breakpoints.
		save breakpoints .early-breakpoints.gdb
		delete breakpoints

		tbreak _start
		commands
			silent

			# Reload the breakpoints now that the GRUB image has
			# finished being loaded into memory.
			source .early-breakpoints.gdb

			runtime_load_module

			if $is_user_command("onstart")
				onstart
			end
			continue
		end
		continue
	end
end
document run_on_start
	On some targets, such as x86_64-efi, even if you know where the
	firmware will load the GRUB image, you can not simply set a break
	point before the image is loaded because loading the image
	overwrites the break point in memory. So setup a hardware watch
	point, which does not have that problem, and if that gets triggered,
	then reset the break point. If a user-defined command named
	"onstart" exists it will be run after the start is hit.
	NOTE: This assumes symbols have already been correctly loaded for
	the EFI application.
end

###

set confirm off

# Note: On EFI and other platforms that load GRUB to an address that is
# determined at runtime, the symbols in kernel.exec will be wrong.
# However, we must start by loading some executable file or GDB will
# fail.

set $platform_efi = $_streq("@platform@", "efi")
set $target = "@target_cpu@-@platform@"

if ! $runonce
	if $platform_efi
		# Only load the executable file, not the symbols
		exec-file kernel.exec
	else
		if $_streq($target, "i386-pc")
			add-symbol-file boot.image
			add-symbol-file diskboot.image
			add-symbol-file lzma_decompress.image
		end
		file kernel.exec
		run_on_start
		runtime_load_module
	end

	target remote :1234
	set $runonce = 1
end