Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to gdb_server.c break debugging of some or all non RISC-V targets #115

Closed
TommyMurphyTM1234 opened this issue Sep 22, 2017 · 28 comments

Comments

@TommyMurphyTM1234
Copy link
Collaborator

The changes to gdb_get_registers_packet(), gdb_set_registers_packet(), gdb_get_register_packet() and gdb_set_register_packet() in this commit:

2ae0078#diff-1f3fc53de9d7ac5aa6603362f46a669d

break debugging of some (or maybe all?) non RISC-V targets. The rationale for these changes is also not clear.

For example before these changes (or if these changes are disabled in the latest version of gdb_server.c) debugging of our Cortex-M targets worked fine.
But with these changes enabled Cortex-M (e.g. Cortex-M3 in this case) debugging fails with the following Eclipse error dialog:

Error in final launch sequence
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
Remote failure reply: E0E
Failed to execute MI command:
-target-select remote localhost:3333
Error message from debugger back end:
Remote failure reply: E0E
Remote failure reply: E0E

and the following OpenOCD log output:

Open On-Chip Debugger 0.10.0+dev-00143-g8721a129-dirty (2017-09-22-11:17)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
M2S090
Info : only one transport option; autoselect 'jtag'
adapter speed: 6000 kHz
cortex_m reset_config sysresetreq
trst_only separate trst_push_pull
do_board_reset_init
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : FlashPro ports available: E200OP5M0
Info : FlashPro port used: E200OP5M0
Info : clock speed 6000 kHz
Info : JTAG tap: M2S090.tap tap/device found: 0x2f8071cf (mfg: 0x0e7 (GateField), part: 0xf807, ver: 0x2)
Info : JTAG tap: M2S090.tap disabled
Info : JTAG tap: M2S090.dap enabled
Info : Cortex-M3 IDCODE = 0x4ba00477
Info : M2S090.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Started by GNU MCU Eclipse
Info : accepting 'gdb' connection on tcp/3333
undefined debug reason 7 - target needs reset
Warn : target not halted

Info : dropped 'gdb' connection

In case it helps the verbose (-d) log output is:

Open On-Chip Debugger 0.10.0+dev-00143-g8721a129-dirty (2017-09-22-11:17)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
User : 13 2 command.c:544 command_print(): debug_level: 3
Debug: 14 2 options.c:217 add_default_dirs(): bindir=D:/msys64/home/tommy.murphy/dev/openocd/openocd-microsemi/openocd/bin
Debug: 15 2 options.c:218 add_default_dirs(): pkgdatadir=D:/msys64/home/tommy.murphy/dev/openocd/openocd-microsemi/openocd/share/openocd
Debug: 16 3 options.c:219 add_default_dirs(): exepath=C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin
Debug: 17 3 options.c:220 add_default_dirs(): bin2data=../share/openocd
Debug: 18 3 configuration.c:42 add_script_search_dir(): adding C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/scripts
Debug: 19 4 configuration.c:42 add_script_search_dir(): adding C:\Users\tommy.murphy\AppData\Roaming/OpenOCD
Debug: 20 4 configuration.c:42 add_script_search_dir(): adding C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/site
Debug: 21 4 configuration.c:42 add_script_search_dir(): adding C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/scripts
Debug: 22 8 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_gdb_port 3333
Debug: 23 8 command.c:143 script_debug(): command - gdb_port ocd_gdb_port 3333
Debug: 25 8 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_telnet_port 4444
Debug: 26 9 command.c:143 script_debug(): command - telnet_port ocd_telnet_port 4444
User : 28 9 command.c:675 command_run_line(): M2S090User : 29 9 command.c:677 command_run_line(): 
Debug: 30 9 configuration.c:82 find_file(): found C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/scripts/board/microsemi-cortex-m3.cfg
Debug: 31 12 configuration.c:82 find_file(): found C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/scripts/interface/microsemi-flashpro.cfg
Debug: 32 13 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_interface microsemi-flashpro
Debug: 33 13 command.c:143 script_debug(): command - interface ocd_interface microsemi-flashpro
Debug: 35 13 command.c:364 register_command_handler(): registering 'ocd_microsemi_flashpro'...
Debug: 36 14 command.c:364 register_command_handler(): registering 'ocd_microsemi_flashpro'...
Debug: 37 14 command.c:364 register_command_handler(): registering 'ocd_microsemi_flashpro_port'...
Info : 38 14 transport.c:117 allow_transports(): only one transport option; autoselect 'jtag'
Debug: 39 14 command.c:364 register_command_handler(): registering 'ocd_jtag_flush_queue_sleep'...
Debug: 40 15 command.c:364 register_command_handler(): registering 'ocd_jtag_rclk'...
Debug: 41 15 command.c:364 register_command_handler(): registering 'ocd_jtag_ntrst_delay'...
Debug: 42 15 command.c:364 register_command_handler(): registering 'ocd_jtag_ntrst_assert_width'...
Debug: 43 15 command.c:364 register_command_handler(): registering 'ocd_scan_chain'...
Debug: 44 16 command.c:364 register_command_handler(): registering 'ocd_jtag_reset'...
Debug: 45 16 command.c:364 register_command_handler(): registering 'ocd_runtest'...
Debug: 46 16 command.c:364 register_command_handler(): registering 'ocd_irscan'...
Debug: 47 17 command.c:364 register_command_handler(): registering 'ocd_verify_ircapture'...
Debug: 48 17 command.c:364 register_command_handler(): registering 'ocd_verify_jtag'...
Debug: 49 17 command.c:364 register_command_handler(): registering 'ocd_tms_sequence'...
Debug: 50 17 command.c:364 register_command_handler(): registering 'ocd_wait_srst_deassert'...
Debug: 51 18 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 52 18 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 53 18 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 54 19 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 55 19 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 56 19 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 57 19 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 58 20 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 59 20 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 60 20 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 61 20 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 62 21 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 63 21 command.c:364 register_command_handler(): registering 'ocd_jtag'...
Debug: 64 21 command.c:364 register_command_handler(): registering 'ocd_svf'...
Debug: 65 21 command.c:364 register_command_handler(): registering 'ocd_xsvf'...
Debug: 66 22 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_adapter_khz 6000
Debug: 67 22 command.c:143 script_debug(): command - adapter_khz ocd_adapter_khz 6000
Debug: 69 22 core.c:1753 jtag_config_khz(): handle jtag khz
Debug: 70 22 core.c:1720 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 71 22 core.c:1720 adapter_khz_to_speed(): convert khz to interface specific speed value
User : 72 23 command.c:544 command_print(): adapter speed: 6000 kHz
Debug: 73 23 configuration.c:82 find_file(): found C:/dev/tools/softconsole/SoftConsole_v5.2.0.8/openocd/bin/../share/openocd/scripts/target/microsemi-cortex-m3.cfg
Debug: 74 24 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag newtap M2S090 tap -irlen 8 -expected-id 0x0f8071cf -ignore-version
Debug: 75 25 command.c:143 script_debug(): command - ocd_jtag ocd_jtag newtap M2S090 tap -irlen 8 -expected-id 0x0f8071cf -ignore-version
Debug: 76 25 tcl.c:549 jim_newtap_cmd(): Creating New Tap, Chip: M2S090, Tap: tap, Dotted: M2S090.tap, 5 params
Debug: 77 25 tcl.c:573 jim_newtap_cmd(): Processing option: -irlen
Debug: 78 26 tcl.c:573 jim_newtap_cmd(): Processing option: -expected-id
Debug: 79 26 tcl.c:573 jim_newtap_cmd(): Processing option: -ignore-version
Debug: 80 26 core.c:1426 jtag_tap_init(): Created Tap: M2S090.tap @ abs position 0, irlen 8, capture: 0x1 mask: 0x3
Debug: 81 26 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag configure M2S090.tap -event tap-disable disable_fpga_tap M2S090.tap 0x0a
Debug: 82 27 command.c:143 script_debug(): command - ocd_jtag ocd_jtag configure M2S090.tap -event tap-disable disable_fpga_tap M2S090.tap 0x0a
Debug: 83 28 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag configure M2S090.tap -event setup switch_from_fpga_tap_to_m3_dap M2S090.tap M2S090.dap
Debug: 84 28 command.c:143 script_debug(): command - ocd_jtag ocd_jtag configure M2S090.tap -event setup switch_from_fpga_tap_to_m3_dap M2S090.tap M2S090.dap
Debug: 85 29 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag newtap M2S090 dap -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x0ba00477 -ignore-version -disable
Debug: 86 29 command.c:143 script_debug(): command - ocd_jtag ocd_jtag newtap M2S090 dap -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 0x0ba00477 -ignore-version -disable
Debug: 87 30 tcl.c:549 jim_newtap_cmd(): Creating New Tap, Chip: M2S090, Tap: dap, Dotted: M2S090.dap, 10 params
Debug: 88 30 tcl.c:573 jim_newtap_cmd(): Processing option: -irlen
Debug: 89 30 tcl.c:573 jim_newtap_cmd(): Processing option: -ircapture
Debug: 90 31 tcl.c:573 jim_newtap_cmd(): Processing option: -irmask
Debug: 91 31 tcl.c:573 jim_newtap_cmd(): Processing option: -expected-id
Debug: 92 31 tcl.c:573 jim_newtap_cmd(): Processing option: -ignore-version
Debug: 93 31 tcl.c:573 jim_newtap_cmd(): Processing option: -disable
Debug: 94 31 core.c:1426 jtag_tap_init(): Created Tap: M2S090.dap @ abs position 1, irlen 4, capture: 0x1 mask: 0xf
Debug: 95 32 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag configure M2S090.dap -event tap-enable enable_m3_dap
Debug: 96 32 command.c:143 script_debug(): command - ocd_jtag ocd_jtag configure M2S090.dap -event tap-enable enable_m3_dap
Debug: 97 32 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_target create M2S090.cpu cortex_m -chain-position M2S090.dap
Debug: 98 33 command.c:143 script_debug(): command - ocd_target ocd_target create M2S090.cpu cortex_m -chain-position M2S090.dap
Debug: 99 33 target.c:1959 target_free_all_working_areas_restore(): freeing all working areas
Debug: 100 33 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 101 34 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 102 34 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 103 34 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 104 34 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 105 34 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 106 35 command.c:364 register_command_handler(): registering 'ocd_arm'...
Debug: 107 35 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 108 35 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 109 35 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 110 36 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 111 36 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 112 36 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 113 36 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 114 37 command.c:364 register_command_handler(): registering 'ocd_dap'...
Debug: 115 37 command.c:364 register_command_handler(): registering 'ocd_tpiu'...
Debug: 116 37 command.c:364 register_command_handler(): registering 'ocd_itm'...
Debug: 117 37 command.c:364 register_command_handler(): registering 'ocd_itm'...
Debug: 118 37 command.c:364 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 119 38 command.c:364 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 120 38 command.c:364 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 121 38 command.c:364 register_command_handler(): registering 'ocd_cortex_m'...
Debug: 122 38 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 123 39 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 124 39 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 125 39 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 126 40 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 127 40 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 128 40 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 129 40 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 130 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 131 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 132 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 133 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 134 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 135 41 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 136 42 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 137 42 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 138 42 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 139 42 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 140 43 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 141 43 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 142 43 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 143 43 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 144 43 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 145 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 146 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 147 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 148 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 149 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 150 44 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 151 45 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 152 45 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 153 45 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 154 45 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 155 45 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 156 46 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 157 46 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 158 46 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 159 46 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 160 46 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 161 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 162 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 163 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 164 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 165 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 166 47 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 167 48 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 168 48 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 169 48 command.c:364 register_command_handler(): registering 'ocd_M2S090.cpu'...
Debug: 170 48 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -work-area-phys 0x20000000 -work-area-size 0x10000 -work-area-backup 0
Debug: 171 49 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -work-area-phys 0x20000000 -work-area-size 0x10000 -work-area-backup 0
Debug: 172 49 target.c:1959 target_free_all_working_areas_restore(): freeing all working areas
Debug: 173 49 target.c:1959 target_free_all_working_areas_restore(): freeing all working areas
Debug: 174 49 target.c:1959 target_free_all_working_areas_restore(): freeing all working areas
Debug: 175 50 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_flash bank M2S090.envm microsemi-smartfusion2-envm 0x60000000 0x80000 0 0 M2S090.cpu
Debug: 176 50 command.c:143 script_debug(): command - ocd_flash ocd_flash bank M2S090.envm microsemi-smartfusion2-envm 0x60000000 0x80000 0 0 M2S090.cpu
Debug: 178 50 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_cortex_m reset_config sysresetreq
Debug: 179 51 command.c:143 script_debug(): command - ocd_cortex_m ocd_cortex_m reset_config sysresetreq
User : 181 51 command.c:544 command_print(): cortex_m reset_config sysresetreq
Debug: 182 51 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_reset_config trst_only
Debug: 183 52 command.c:143 script_debug(): command - reset_config ocd_reset_config trst_only
User : 185 52 command.c:544 command_print(): trst_only separate trst_push_pull
Debug: 186 52 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -event reset-init 
	# device reset-init
	do_device_reset_init

	# call board level reset-init if defined
	if {[exists -proc do_board_reset_init]} {
		do_board_reset_init
	}

Debug: 187 53 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -event reset-init 
	# device reset-init
	do_device_reset_init

	# call board level reset-init if defined
	if {[exists -proc do_board_reset_init]} {
		do_board_reset_init
	}

Debug: 188 54 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -event examine-end 
	# Check that we are, in fact, talking to a Cortex-M3
	# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100165_0201_00_en/ric1417175933150.html
	
	mem2array a 32 0xe000ed00 1
	set cpuid [expr (($a(0) >> 4) & 0x00000fff)]
	if {$cpuid ne 0x00000c23} {
		error [format "Error: failed to detect Cortex-M3, CPUID = 0x%04x" $a(0)]
	}

Debug: 189 55 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -event examine-end 
	# Check that we are, in fact, talking to a Cortex-M3
	# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100165_0201_00_en/ric1417175933150.html
	
	mem2array a 32 0xe000ed00 1
	set cpuid [expr (($a(0) >> 4) & 0x00000fff)]
	if {$cpuid ne 0x00000c23} {
		error [format "Error: failed to detect Cortex-M3, CPUID = 0x%04x" $a(0)]
	}

Debug: 190 56 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -event gdb-detach 
	# resume execution on debugger detach
	resume

Debug: 191 57 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -event gdb-detach 
	# resume execution on debugger detach
	resume

User : 192 57 command.c:675 command_run_line(): do_board_reset_initUser : 193 57 command.c:677 command_run_line(): 
Info : 194 59 server.c:312 add_service(): Listening on port 6666 for tcl connections
Info : 195 60 server.c:312 add_service(): Listening on port 4444 for telnet connections
Debug: 196 60 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_init
Debug: 197 60 command.c:143 script_debug(): command - init ocd_init
Debug: 199 61 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_target init
Debug: 200 61 command.c:143 script_debug(): command - ocd_target ocd_target init
Debug: 202 61 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_target names
Debug: 203 61 command.c:143 script_debug(): command - ocd_target ocd_target names
Debug: 204 62 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu cget -event gdb-flash-erase-start
Debug: 205 62 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu cget -event gdb-flash-erase-start
Debug: 206 62 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -event gdb-flash-erase-start reset init
Debug: 207 63 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -event gdb-flash-erase-start reset init
Debug: 208 63 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu cget -event gdb-flash-write-end
Debug: 209 64 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu cget -event gdb-flash-write-end
Debug: 210 64 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_M2S090.cpu configure -event gdb-flash-write-end reset halt
Debug: 211 65 command.c:143 script_debug(): command - ocd_M2S090.cpu ocd_M2S090.cpu configure -event gdb-flash-write-end reset halt
Debug: 212 65 target.c:1368 handle_target_init_command(): Initializing targets...
Debug: 213 65 command.c:364 register_command_handler(): registering 'ocd_target_request'...
Debug: 214 65 command.c:364 register_command_handler(): registering 'ocd_trace'...
Debug: 215 65 command.c:364 register_command_handler(): registering 'ocd_trace'...
Debug: 216 66 command.c:364 register_command_handler(): registering 'ocd_fast_load_image'...
Debug: 217 66 command.c:364 register_command_handler(): registering 'ocd_fast_load'...
Debug: 218 66 command.c:364 register_command_handler(): registering 'ocd_profile'...
Debug: 219 66 command.c:364 register_command_handler(): registering 'ocd_virt2phys'...
Debug: 220 66 command.c:364 register_command_handler(): registering 'ocd_reg'...
Debug: 221 66 command.c:364 register_command_handler(): registering 'ocd_poll'...
Debug: 222 67 command.c:364 register_command_handler(): registering 'ocd_wait_halt'...
Debug: 223 67 command.c:364 register_command_handler(): registering 'ocd_halt'...
Debug: 224 67 command.c:364 register_command_handler(): registering 'ocd_resume'...
Debug: 225 67 command.c:364 register_command_handler(): registering 'ocd_reset'...
Debug: 226 67 command.c:364 register_command_handler(): registering 'ocd_soft_reset_halt'...
Debug: 227 67 command.c:364 register_command_handler(): registering 'ocd_step'...
Debug: 228 68 command.c:364 register_command_handler(): registering 'ocd_mdd'...
Debug: 229 68 command.c:364 register_command_handler(): registering 'ocd_mdw'...
Debug: 230 68 command.c:364 register_command_handler(): registering 'ocd_mdh'...
Debug: 231 68 command.c:364 register_command_handler(): registering 'ocd_mdb'...
Debug: 232 68 command.c:364 register_command_handler(): registering 'ocd_mwd'...
Debug: 233 68 command.c:364 register_command_handler(): registering 'ocd_mww'...
Debug: 234 69 command.c:364 register_command_handler(): registering 'ocd_mwh'...
Debug: 235 69 command.c:364 register_command_handler(): registering 'ocd_mwb'...
Debug: 236 69 command.c:364 register_command_handler(): registering 'ocd_bp'...
Debug: 237 69 command.c:364 register_command_handler(): registering 'ocd_rbp'...
Debug: 238 69 command.c:364 register_command_handler(): registering 'ocd_wp'...
Debug: 239 69 command.c:364 register_command_handler(): registering 'ocd_rwp'...
Debug: 240 70 command.c:364 register_command_handler(): registering 'ocd_load_image'...
Debug: 241 70 command.c:364 register_command_handler(): registering 'ocd_dump_image'...
Debug: 242 70 command.c:364 register_command_handler(): registering 'ocd_verify_image_checksum'...
Debug: 243 70 command.c:364 register_command_handler(): registering 'ocd_verify_image'...
Debug: 244 70 command.c:364 register_command_handler(): registering 'ocd_test_image'...
Debug: 245 70 command.c:364 register_command_handler(): registering 'ocd_reset_nag'...
Debug: 246 71 command.c:364 register_command_handler(): registering 'ocd_ps'...
Debug: 247 71 command.c:364 register_command_handler(): registering 'ocd_test_mem_access'...
Info : 248 463 microsemi_flashpro.c:1602 microsemi_flashpro_initialize(): FlashPro ports available: E200OP5M0
Info : 249 463 microsemi_flashpro.c:1603 microsemi_flashpro_initialize(): FlashPro port used: E200OP5M0
Debug: 250 545 core.c:1720 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 251 545 core.c:1723 adapter_khz_to_speed(): have interface set up
Debug: 252 545 core.c:1720 adapter_khz_to_speed(): convert khz to interface specific speed value
Debug: 253 545 core.c:1723 adapter_khz_to_speed(): have interface set up
Info : 254 546 core.c:1508 adapter_init(): clock speed 6000 kHz
Debug: 255 546 openocd.c:164 handle_init_command(): Debug Adapter init complete
Debug: 256 546 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_transport init
Debug: 257 546 command.c:143 script_debug(): command - ocd_transport ocd_transport init
Debug: 260 546 transport.c:239 handle_transport_init(): handle_transport_init
Debug: 261 547 core.c:729 jtag_add_reset(): SRST line released
Debug: 262 547 core.c:753 jtag_add_reset(): TRST line released
Debug: 263 547 core.c:327 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 264 547 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag arp_init
Debug: 265 547 command.c:143 script_debug(): command - ocd_jtag ocd_jtag arp_init
Debug: 266 547 core.c:1521 jtag_init_inner(): Init JTAG chain
Debug: 267 547 core.c:327 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 268 548 core.c:1177 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
Debug: 269 548 core.c:327 jtag_call_event_callbacks(): jtag event: TAP reset
Info : 270 549 core.c:1076 jtag_examine_chain_display(): JTAG tap: M2S090.tap tap/device found: 0x2f8071cf (mfg: 0x0e7 (GateField), part: 0xf807, ver: 0x2)
Debug: 271 549 core.c:1312 jtag_validate_ircapture(): IR capture validation scan
Debug: 272 550 core.c:1370 jtag_validate_ircapture(): M2S090.tap: IR capture 0x95
Debug: 273 550 tcl.c:632 jtag_tap_handle_event(): JTAG tap: M2S090.tap event: 1 (setup)
	action: switch_from_fpga_tap_to_m3_dap M2S090.tap M2S090.dap
Debug: 274 550 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag tapdisable M2S090.tap
Debug: 275 550 command.c:143 script_debug(): command - ocd_jtag ocd_jtag tapdisable M2S090.tap
Debug: 276 551 tcl.c:632 jtag_tap_handle_event(): JTAG tap: M2S090.tap event: 3 (tap-disable)
	action: disable_fpga_tap M2S090.tap 0x0a
Debug: 277 551 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_irscan M2S090.tap 0x0a -endstate IRPAUSE
Debug: 278 551 command.c:143 script_debug(): command - irscan ocd_irscan M2S090.tap 0x0a -endstate IRPAUSE
Debug: 280 551 command.c:143 script_debug(): command - drscan drscan M2S090.tap 8 0x00 -endstate DRPAUSE
Debug: 281 552 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_runtest 8
Debug: 282 552 command.c:143 script_debug(): command - runtest ocd_runtest 8
Info : 284 552 tcl.c:649 jtag_tap_handle_event(): JTAG tap: M2S090.tap disabled
Debug: 285 552 core.c:327 jtag_call_event_callbacks(): jtag event: TAP disabled
Debug: 286 553 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_jtag tapenable M2S090.dap
Debug: 287 553 command.c:143 script_debug(): command - ocd_jtag ocd_jtag tapenable M2S090.dap
Debug: 288 553 tcl.c:632 jtag_tap_handle_event(): JTAG tap: M2S090.dap event: 2 (tap-enable)
	action: enable_m3_dap
Info : 289 553 tcl.c:649 jtag_tap_handle_event(): JTAG tap: M2S090.dap enabled
Debug: 290 553 core.c:327 jtag_call_event_callbacks(): jtag event: TAP enabled
Debug: 291 553 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_irscan M2S090.dap 0x0e
Debug: 292 554 command.c:143 script_debug(): command - irscan ocd_irscan M2S090.dap 0x0e
Debug: 294 554 command.c:143 script_debug(): command - drscan drscan M2S090.dap 32 0
Debug: 295 554 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_echo Info : Cortex-M3 IDCODE = 0x4ba00477
Debug: 296 555 command.c:143 script_debug(): command - echo ocd_echo Info : Cortex-M3 IDCODE = 0x4ba00477
User : 298 555 command.c:762 jim_echo(): Info : Cortex-M3 IDCODE = 0x4ba00477
Debug: 299 555 openocd.c:177 handle_init_command(): Examining targets...
Debug: 300 555 target.c:1561 target_call_event_callbacks(): target event 21 (examine-start)
Debug: 301 555 arm_adi_v5.c:603 dap_dp_init():  
Debug: 302 556 arm_adi_v5.c:637 dap_dp_init(): DAP: wait CDBGPWRUPACK
Debug: 303 556 arm_adi_v5.h:428 dap_dp_poll_register(): DAP: poll 4, mask 0x20000000, value 0x20000000
Debug: 304 559 arm_adi_v5.c:644 dap_dp_init(): DAP: wait CSYSPWRUPACK
Debug: 305 559 arm_adi_v5.h:428 dap_dp_poll_register(): DAP: poll 4, mask 0x80000000, value 0x80000000
Debug: 306 563 arm_adi_v5.c:785 dap_find_ap(): Found AHB-AP at AP index: 0 (IDR=0x24770011)
Debug: 307 565 arm_adi_v5.c:712 mem_ap_init(): MEM_AP Packed Transfers: enabled
Debug: 308 565 arm_adi_v5.c:723 mem_ap_init(): MEM_AP CFG: large data 0, long address 0, big-endian 0
Debug: 309 567 target.c:2306 target_read_u32(): address: 0xe000ed00, value: 0x412fc231
Debug: 310 567 cortex_m.c:1958 cortex_m_examine(): Cortex-M3 r2p1 processor detected
Debug: 311 567 cortex_m.c:1966 cortex_m_examine(): cpuid: 0x412fc231
Debug: 312 567 target.c:2394 target_write_u32(): address: 0xe000edfc, value: 0x01000000
Debug: 313 569 target.c:2306 target_read_u32(): address: 0xe0002000, value: 0x00000260
Debug: 314 569 target.c:2394 target_write_u32(): address: 0xe0002008, value: 0x00000000
Debug: 315 571 target.c:2394 target_write_u32(): address: 0xe000200c, value: 0x00000000
Debug: 316 571 target.c:2394 target_write_u32(): address: 0xe0002010, value: 0x00000000
Debug: 317 573 target.c:2394 target_write_u32(): address: 0xe0002014, value: 0x00000000
Debug: 318 574 target.c:2394 target_write_u32(): address: 0xe0002018, value: 0x00000000
Debug: 319 575 target.c:2394 target_write_u32(): address: 0xe000201c, value: 0x00000000
Debug: 320 576 target.c:2394 target_write_u32(): address: 0xe0002020, value: 0x00000000
Debug: 321 577 target.c:2394 target_write_u32(): address: 0xe0002024, value: 0x00000000
Debug: 322 578 cortex_m.c:2057 cortex_m_examine(): FPB fpcr 0x260, numcode 6, numlit 2
Debug: 323 579 target.c:2306 target_read_u32(): address: 0xe0001000, value: 0x40000000
Debug: 324 579 target.c:2394 target_write_u32(): address: 0xe0001028, value: 0x00000000
Debug: 325 580 target.c:2394 target_write_u32(): address: 0xe0001038, value: 0x00000000
Debug: 326 581 target.c:2394 target_write_u32(): address: 0xe0001048, value: 0x00000000
Debug: 327 582 target.c:2394 target_write_u32(): address: 0xe0001058, value: 0x00000000
Debug: 328 583 cortex_m.c:1868 cortex_m_dwt_setup(): DWT dwtcr 0x40000000, comp 4, watch/trigger
Info : 329 583 cortex_m.c:2067 cortex_m_examine(): M2S090.cpu: hardware has 6 breakpoints, 4 watchpoints
Debug: 330 583 target.c:1561 target_call_event_callbacks(): target event 22 (examine-end)
Debug: 331 584 target.c:4495 target_handle_event(): target: (0) M2S090.cpu (cortex_m) event: 22 (examine-end) action: 
	# Check that we are, in fact, talking to a Cortex-M3
	# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100165_0201_00_en/ric1417175933150.html
	
	mem2array a 32 0xe000ed00 1
	set cpuid [expr (($a(0) >> 4) & 0x00000fff)]
	if {$cpuid ne 0x00000c23} {
		error [format "Error: failed to detect Cortex-M3, CPUID = 0x%04x" $a(0)]
	}

Debug: 332 586 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_flash init
Debug: 333 586 command.c:143 script_debug(): command - ocd_flash ocd_flash init
Debug: 335 588 tcl.c:1107 handle_flash_init_command(): Initializing flash devices...
Debug: 336 588 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 337 588 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 338 588 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 339 589 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 340 589 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 341 589 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 342 589 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 343 589 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 344 590 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 345 590 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 346 590 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 347 590 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 348 590 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 349 591 command.c:364 register_command_handler(): registering 'ocd_flash'...
Debug: 350 591 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_mflash init
Debug: 351 591 command.c:143 script_debug(): command - ocd_mflash ocd_mflash init
Debug: 353 593 mflash.c:1377 handle_mflash_init_command(): Initializing mflash devices...
Debug: 354 593 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_nand init
Debug: 355 593 command.c:143 script_debug(): command - ocd_nand ocd_nand init
Debug: 357 595 tcl.c:497 handle_nand_init_command(): Initializing NAND devices...
Debug: 358 595 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_pld init
Debug: 359 595 command.c:143 script_debug(): command - ocd_pld ocd_pld init
Debug: 361 596 pld.c:205 handle_pld_init_command(): Initializing PLDs...
Info : 362 597 server.c:312 add_service(): Listening on port 3333 for gdb connections
User : 363 597 openocd.c:362 openocd_thread(): Started by GNU MCU Eclipse
Info : 364 1043 server.c:96 add_connection(): accepting 'gdb' connection on tcp/3333
Debug: 365 1043 breakpoints.c:357 breakpoint_clear_target_internal(): Delete all breakpoints for target: M2S090.cpu
Debug: 366 1043 breakpoints.c:497 watchpoint_clear_target(): Delete all watchpoints for target: M2S090.cpu
Debug: 367 1044 target.c:1561 target_call_event_callbacks(): target event 23 (gdb-attach)
Debug: 368 1044 gdb_server.c:996 gdb_new_connection(): New GDB Connection: 1, Target M2S090.cpu, state: reset
Debug: 369 1044 gdb_server.c:2868 gdb_input_inner(): received packet: 'qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+'
Debug: 370 1045 gdb_server.c:2868 gdb_input_inner(): received packet: 'vMustReplyEmpty'
Debug: 371 1045 gdb_server.c:2868 gdb_input_inner(): received packet: 'QStartNoAckMode'
Debug: 372 1045 gdb_server.c:632 gdb_get_packet_inner(): Received first acknowledgment after entering noack mode. Ignoring it.
Debug: 373 1046 gdb_server.c:2868 gdb_input_inner(): received packet: 'Hg0'
Debug: 374 1046 gdb_server.c:2868 gdb_input_inner(): received packet: 'qXfer:features:read:target.xml:0,fff'
Debug: 375 1047 gdb_server.c:2868 gdb_input_inner(): received packet: 'qTStatus'
Debug: 376 1048 gdb_server.c:2868 gdb_input_inner(): received packet: '?'
User : 377 1048 gdb_server.c:153 gdb_last_signal(): undefined debug reason 7 - target needs reset
Debug: 378 1048 gdb_server.c:2868 gdb_input_inner(): received packet: 'qXfer:threads:read::0,fff'
Debug: 379 1048 gdb_server.c:2868 gdb_input_inner(): received packet: 'Hc-1'
Debug: 380 1049 gdb_server.c:2868 gdb_input_inner(): received packet: 'qC'
Debug: 381 1049 gdb_server.c:2868 gdb_input_inner(): received packet: 'qAttached'
Debug: 382 1052 gdb_server.c:2868 gdb_input_inner(): received packet: 'g'
Debug: 383 1053 gdb_server.c:1174 gdb_get_registers_packet(): Couldn't get register r0.
Debug: 384 1053 gdb_server.c:1386 gdb_error(): Reporting -304 to GDB as generic error
Debug: 385 1053 gdb_server.c:1022 gdb_connection_closed(): GDB Close, Target: M2S090.cpu, state: reset, gdb_actual_connections=0
Debug: 386 1054 target.c:1561 target_call_event_callbacks(): target event 6 (gdb-end)
Debug: 387 1055 target.c:1561 target_call_event_callbacks(): target event 24 (gdb-detach)
Debug: 388 1056 target.c:4495 target_handle_event(): target: (0) M2S090.cpu (cortex_m) event: 24 (gdb-detach) action: 
	# resume execution on debugger detach
	resume

Debug: 389 1056 command.c:143 script_debug(): command - ocd_command ocd_command type ocd_resume
Debug: 390 1056 command.c:143 script_debug(): command - resume ocd_resume
Debug: 392 1058 target.c:1561 target_call_event_callbacks(): target event 3 (resume-start)
Warn : 393 1058 cortex_m.c:693 cortex_m_resume(): target not halted
Debug: 394 1058 command.c:626 run_command(): Command failed with error code -304
User : 395 1059 command.c:544 command_print(): 

Info : 396 1059 server.c:533 server_loop(): dropped 'gdb' connection
@timsifive
Copy link
Collaborator

I don't have time to really dig into this right now, but I can provide a little background.

The change in question causes errors encountered while reading/writing registers to be propagated to gdb. Previously if a register could not be read (eg. because it doesn't exist) gdb would think the read was successful, and we'd have to provide some value that is hopefully recognized as bogus.

In the log you provided, the new code tells you what register couldn't be accessed. It returns an error to gdb, which in turn decides to abort the session. (I don't know why gdb decides to do so.) I've highlighted that part below:

Debug: 382 1052 gdb_server.c:2868 gdb_input_inner(): received packet: 'g'
Debug: 383 1053 gdb_server.c:1174 gdb_get_registers_packet(): Couldn't get register r0.
Debug: 384 1053 gdb_server.c:1386 gdb_error(): Reporting -304 to GDB as generic error
Debug: 385 1053 gdb_server.c:1022 gdb_connection_closed(): GDB Close, Target: M2S090.cpu, state: reset, gdb_actual_connections=0

The 'g' packet is gdb requesting to see "all" registers, so it's not even a case of gdb requesting a register that doesn't exist. Maybe the target is running and that is why the request fails. It would need more debugging to figure out.

@mwachs5
Copy link
Collaborator

mwachs5 commented Sep 22, 2017

@TM1234 Can you provide the log file on your non RISC-V target without this change applied? Do you still get the error message that @timsifive identified, but it is silently ignored?

At any rate, I suspected that this might cause issues with upstream OpenOCD, since it is returning errors in places that it used to ignore them. I think we should file an issue upstream, since it seems like bad behavior to drop error messages.

@TommyMurphyTM1234
Copy link
Collaborator Author

TommyMurphyTM1234 commented Sep 23, 2017

Hi Megan - attached is the openocd -d log for a debug session with a Cortex-M3 target with the aforementioned gdb_server.c mods disabled. I don't see any error being ignored - do you?

Tim - I wonder if the "Couldn't get register r0" happens because the target is not in debug halt at that stage but the mods to gdb_server.c don't take account of this being a possible reason for not being able to read the regs?

Hope this helps.

For now I have to build openocd with these mods disabled because they break non RISC-V debugging - or possibly debugging of any target that is not halted when the attempt is made to read the regs. I'm still not clear on what adverse impact this might have on RISC-V debugging?

m3-debug.log

@TommyMurphyTM1234
Copy link
Collaborator Author

TommyMurphyTM1234 commented Sep 23, 2017

Sorry - I missed that Tim had posted this earlier:

The 'g' packet is gdb requesting to see "all" registers, so it's not even a case of gdb requesting a register that doesn't exist. Maybe the target is running and that is why the request fails. It would need more debugging to figure out.

In this specific case I think that this is the problem alright but the point is that the mods mentioned are assuming that the regs can be read and/or that the target is halted when this may not be the case - hence the mods are not really safe.

They work for RISC-V because in many cases the openocd debug config script will have a halt but not all target scripts will have this - nor should they. In fact we have a halt in our RISC-V debug script only because our RISC-V target does not provide the debugger with the ability to do a proper initial reset/halt via JTAG.

@mwachs5
Copy link
Collaborator

mwachs5 commented Sep 29, 2017

It sounds like we should revert this change to gdb_server.c, and understand why it was not fixed in upstream openOCD. This issue that this change was initially set up to handle has since been handled by a workaround in GDB (you can now explicitly set whether your core supports 'C' extension, even if MISA is not in the 1.9.1 location).

@timsifive
Copy link
Collaborator

This is a more general issue, though. When a user asks to read a CSR, there really isn't a good alternative besides having the debugger try to do the read, and return either success or error. Without this change, the best we can do is return some value like 0 or ~0 and hope the user realizes the CSR isn't present.

@mwachs5
Copy link
Collaborator

mwachs5 commented Sep 29, 2017

I agree that this is a problem. I don't understand why it works for non RISC-V Targets.

@timsifive
Copy link
Collaborator

Does it work for non-RISC-V targets? Eg. MIPS has a coprocessor register space much like CSRs. How is the problem solved there? A user should be able to request to view an arbitrary one, and get back either its value or some message indicating it doesn't exist. And that message should be true (ie. allowing for cores which implement unknown-to-the-debugger extensions).

@TommyMurphyTM1234
Copy link
Collaborator Author

I agree that this is a problem. I don't understand why it works for non RISC-V Targets

Hi Megan - can you clarify what you mean please?
Your don't understand why what works for non RISC-V targets?

Seems to me that the mods to gdb_server.c are assuming that the registers are always readable.
I'm not sure that this is the case for all targets all of the time - e.g. when not in debug halt?
Seems to be the case for Cortex-M that the regs cannot be read when the target is not in debug halt - but I can't remember the details of how CoreSight works in this respect offhand.
If the code is assuming that the registers are always readable and/or that the target is in debug halt then these are not safe assumptions as far as I can tell (and the fact that Cortex-M debugging fails when it works without these mods is a specific case in point)..

Hope this helps.

@mwachs5
Copy link
Collaborator

mwachs5 commented Sep 29, 2017

The mods to gdb_server.c simply return the error that OpenOCD has taken the time to report. If it is not an error for the registers to be read when a given target is not halted, then OpenOCD wouldn't return an error, and the gdb_server.c mods would have no effect. If it IS an error for the registers to be read when the hart is halted, well, then the upstream tool/script/GDB should be notified and handle it properly. It sounds like the real issue is the latter : for other targets, the upstream tools or scripts (I don't know which) are doing bad things and never realized it before, so they haven't properly handled the error.

This particular gdb_server code makes no assumptions about whether the registers can be read or not. If an error is returned, it simply passes it on.

@TommyMurphyTM1234
Copy link
Collaborator Author

TommyMurphyTM1234 commented Sep 29, 2017

OK - I don't really understand why these changes break Cortex-M debugging but it works without them.
I don't know if the two logs posted earlier shed any light on this?
As I mentioned before, for the moment, I have to disable these mods when building openocd so that it works for both RISC-V and Cortex-M.
My understanding is that this may cause problems only with our priv spec 1.9/debug spec 0.11 RV32IM?

@mwachs5
Copy link
Collaborator

mwachs5 commented Sep 29, 2017

I looked at the two logs. In the "passing" log, the 'g' packet which fails on the "failing" log seems to be completely ignored. GDB closes down the session when the error from the g packet is passed back in the failing log. So the question is really why does the ARM GDB close down as soon as it gets an error. perhaps there is a "gentler" error type that can be returned to GDB so it would just ignore the error on its side.

@ilg-ul
Copy link
Contributor

ilg-ul commented Oct 4, 2017

for the records:

ilg-archived/openocd@da43038

@mwachs5
Copy link
Collaborator

mwachs5 commented Oct 4, 2017

Is there a way to ask about this to the OpenOCD maintainers? Not sure their issue/ Q&A mechanism.

@TommyMurphyTM1234
Copy link
Collaborator Author

TommyMurphyTM1234 commented Oct 4, 2017

Is there a way to ask about this to the OpenOCD maintainers? Not sure their issue/ Q&A mechanism.

Any use?

http://openocd.org/discussion/

https://sourceforge.net/p/openocd/tickets/

@ilg-ul
Copy link
Contributor

ilg-ul commented Oct 4, 2017

why does the ARM GDB close down as soon as it gets an error. perhaps there is a "gentler" error type that can be returned to GDB so it would just ignore the error on its side.

is this the question you want to ask? isn't this more of a GDB question?

on the other side, if the discussion is only about the 4 patches that I just disabled, I think that we are 'fighting against the wind mills', the chances of pushing something like this upstream are not that high.

@ilg-ul
Copy link
Contributor

ilg-ul commented Jan 19, 2018

Tim, do you have a plan how to fix this?

Did you identify the reasons why these patches were applied?

Personally I would reverse the patches completely, since both myself and Microsemi use OpenOCD like this without any problems.

If you have serious reasons to maintain these patches, in order to make them harmless for other platforms, and make them upstreamable, I suggest you add a new flag to the target structure (like is_error_strict, or whatever), and do the extra processing only when this flag is set, otherwise revert to the original behaviour.

@TommyMurphyTM1234
Copy link
Collaborator Author

I fully agree with Liviu - I had been meaning to revisit this issue but this has nudged me into action. As stated simply earlier several times the changes break at least Cortex-M (and maybe other CPU) debugging but RISC-V debugging (so far) works fine with the changes disabled so they seem to me to be redundant. And they will definitely not be upstreamable as they stand. I vote for their removal too. But if they have to be retained (and the case for retention is very weak as far as I can see) then they should be made optional/configurable as Liviu suggests.

@timsifive
Copy link
Collaborator

timsifive commented Jan 19, 2018 via email

timsifive added a commit that referenced this issue Mar 1, 2018
Without this change, connecting to ARM targets is impossible.

Fixes #115.

Change-Id: Ie33c7e15ac1bed8c9cbd8e6a78de92d5498c5999
@ilg-ul
Copy link
Contributor

ilg-ul commented Mar 2, 2018

thank you, Tim. I'll include it in my next release. it would be great to upstream the patch too.

@ilg-ul
Copy link
Contributor

ilg-ul commented Mar 26, 2018

I'm afraid this patch will not be accepted upstream:

http://openocd.zylin.com/#/c/4452/

I suggest you either upstream the RISC-V code and later retry to plead for your patch, or simply reverse these changes in your fork, since they seem not necessary anyway.

@TommyMurphyTM1234
Copy link
Collaborator Author

This is basically what I said a good while back:

Matthias Welwarsky
Mar 24 8:26 AM

Patch Set 1: Code-Review-1

Ok, but I don't see why a change in generic code is required because the RISC-V support (which is not even in gerrit yet) is broken.

I have never understood why ANY changes were required to generic/non target specific code to accommodate RISC-V changes - and unfortunately commit comments never really explained either.

@ilg-ul
Copy link
Contributor

ilg-ul commented Apr 10, 2018

The modified patch was cherry picked on Apr 7.

http://openocd.zylin.com/gitweb?p=openocd.git;a=commitdiff;h=2e2bb14b276f5bd973308dcfabd1b8018e187243

Tim, can you confirm that after the latest merge from master, everything is ok?

@timsifive
Copy link
Collaborator

I don't have an ARM target so I can't reproduce this problem. As far as I'm aware both mainline and the RISC-V branch now have the gdb_report_register_access_error command.

@ilg-ul
Copy link
Contributor

ilg-ul commented Apr 10, 2018

The question was "after the latest merge from master, everything is ok for RISC-V targets?"

Do you automatically initialise the flag related to gdb_report_register_access_error for RISC-V targets?

@timsifive
Copy link
Collaborator

Just like gdb_report_data_abort, it's left up to the config file to enable gdb_report_register_access_error. I enable it in my test scripts and it works well.

@ilg-ul
Copy link
Contributor

ilg-ul commented Apr 10, 2018

So, by default, both are disabled, for all targets.

@timsifive
Copy link
Collaborator

That's right. Both options default to disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants