3.18 Working with semihosting

Semihosting is supported by the debugger in both the command-line console and from the user interface.

Enabling semihosting support

By default, semihosting support is disabled in the debugger. However, DS-5 Debugger enables semihosting automatically if either __auto_semihosting or __semihosting_library_function ELF symbols are present in an image. Also, if the image is compiled with ARM® Compiler 5.0 and later, the linker automatically adds __semihosting_library_function to an image if it uses functions that require semihosting.

In C code, you can create the ELF symbol by defining a function with the name __auto_semihosting. To prevent this function generating any additional code or data in your image, you can define it as an alias of another function. This places the required ELF symbol in the debug information, but does not affect the code and data in the application image.

Example 3-5 Create a special semihosting ELF symbol with an alias to main()

#include <stdio.h>
void __auto_semihosting(void) __attribute__((alias("main")));
                                     //mark as alias for main() to declare 
                                     //semihosting ELF symbol in debug information only
int main(void)
{
    printf("Hello world\n");
    return 0;
}

Using semihosting from the command-line console

The input/output requests from application code to a host workstation running the debugger are called semihosting messages. By default, all semihosting messages (stdout and stderr) are output to the console. When using this console interactively with debugger commands, you must use the stdin option to send input messages to the application.

By default, all messages are output to the command-line console, but you can choose to redirect them when launching the debugger by using one or more of the following options:

--disable_semihosting

Disables all semihosting operations.

--disable_semihosting_console

Disables all semihosting operations to the debugger console.

--semihosting_error=filename

Specifies a file to write stderr for semihosting operations.

--semihosting_input=filename

Specifies a file to read stdin for semihosting operations.

--semihosting_output=filename

Specifies a file to write stdout for semihosting operations.

Note:

Alternatively, you can disable semihosting in the console and use a separate telnet session to interact directly with the application. During start up, the debugger creates a semihosting server socket and displays the port number to use for the telnet session.

See Command-line debugger options for more information.

Using semihosting from the user interface

The App Console view in the DS-5 Debug perspective controls all the semihosting input/output requests (stdin, stdout, and stderr) between the application code and the debugger.

Non-ConfidentialPDF file icon PDF versionARM DUI0446Z
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.