3.16 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:
Disables all semihosting operations.
Disables all semihosting operations to the debugger console.
Specifies a file to write stderr for semihosting operations.
Specifies a file to read stdin for semihosting operations.
Specifies a file to write stdout for semihosting operations.


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.
Related reference
16.5 About passing arguments to main()
3.15 Using semihosting to access resources on the host computer
11.42 Debug Configurations - Arguments tab
11.1 App Console view
Related information
DS-5 Debugger commands
Non-ConfidentialPDF file icon PDF versionARM DUI0446W
Copyright © 2010-2015 ARM. All rights reserved.