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

OpenOCD halts CPU when connecting to gdb-server (OCD-979) #330

Closed
ghost opened this issue Jun 29, 2024 · 7 comments
Closed

OpenOCD halts CPU when connecting to gdb-server (OCD-979) #330

ghost opened this issue Jun 29, 2024 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 29, 2024

OpenOCD version

v0.12.0-esp32-20240318

Operating System

Windows 10

Using an IDE ?

VScode esp-idf extension

OpenOCD command line

openocd -f esp32s3-builtin.cfg

ESP-IDF version

v4.4

Problem Description

During the development of an open source project, we wanted to use the gdb-server to extract data from esp32 RAM. Then we fell into an issue, where the application successfully extracts the data, but when we connect to the gdb socket the target halts. This happens before sending any gdb commands over the tcp/ip gdb protocol. We wish to not make the target halt when the attach happens, so we would be happy if you could help us configure OpenOCD for esp32, so that the attachment does not halt the target. Thanks!

Debug Logs

No response

Expected behavior

Custom OpenOCD 'cfg' file as to not halt the target when the attach happens.

Screenshots

No response

@github-actions github-actions bot changed the title OpenOCD halts CPU when connecting to gdb-server OpenOCD halts CPU when connecting to gdb-server (OCD-979) Jun 29, 2024
@erhankur
Copy link
Collaborator

erhankur commented Jul 1, 2024

To avoid halt, you can comment out https://github.com/espressif/openocd-esp32/blob/master/tcl/target/esp_common.cfg#L195 and https://github.com/espressif/openocd-esp32/blob/master/tcl/target/esp_common.cfg#L214

As the explanation says, halt is needed for the flash probe. That means, you need to disable the flash support.

openocd -c "set ESP_FLASH_SIZE 0" -f board/esp32s3-builtin.cfg

@ghost
Copy link
Author

ghost commented Jul 5, 2024

Hi, thank you @erhankur for your help. When following the steps you mentioned, and then trying to connect to GDB server, we ran into an issue. These are the steps we took:

  1. Comment out both "halt 1000" commands
  2. Added "set ESP_FLASH_SIZE 0" to the arg list for OpenOCD
  3. Started the OpenOCD server
  4. Tried to connect to GDB server
  5. Winsocket function recv() returns value 0 -> Connection to the server has been gracefully closed.

However, it is interesting that this does not happen if the MCU is halted already.

@erhankur
Copy link
Collaborator

erhankur commented Jul 8, 2024

Sorry no idea what is happening. If you can share the verbose OpenOCD logs, I can suggest something more.

openocd -c "set ESP_FLASH_SIZE 0" -f board/esp32s3-builtin.cfg -d3 -l log.txt

@ghost
Copy link
Author

ghost commented Jul 13, 2024

Sorry for the wait @erhankur , I am attaching the log file.
logfile.log

@erhankur
Copy link
Collaborator

Thanks for the log. We can comment out configure_event_gdb_attach call inside configure_openocd_events.

proc configure_openocd_events { ARCH } {
	if { $ARCH == "riscv" } {
		configure_event_halted
		configure_shutdown_command
	}
	configure_event_examine_end
	configure_event_reset_assert_post
	# configure_event_gdb_attach
}

We disabled flash support so we don't need mem prot check anymore. After that, there is nothing to do in the gdb attach event.

@erhankur
Copy link
Collaborator

erhankur commented Aug 1, 2024

@Stefasaurus Can we close this issue now? Do you have any other question?

@erhankur
Copy link
Collaborator

erhankur commented Aug 7, 2024

Closed. Feel free to re-open if you have any other question.

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

No branches or pull requests

2 participants