-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a sample to test C++ exceptions support
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# RUN: make -C %samples_dir/src/cpp-baremetal-semihosting-exceptions clean | ||
# RUN: make -C %samples_dir/src/cpp-baremetal-semihosting-exceptions run BIN_PATH=%unpack_directory/bin 2>&1 | FileCheck %s | ||
# RUN: make -C %samples_dir/src/cpp-baremetal-semihosting-exceptions clean | ||
# CHECK: No exceptions. | ||
# CHECK: Exception caught. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# Copyright (c) 2024, Arm Limited and affiliates. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
include ../../Makefile.conf | ||
|
||
build: hello.hex hello-exn.hex | ||
|
||
hello.hex: hello.cpp | ||
$(BIN_PATH)/clang++ $(MICROBIT_TARGET) $(CRT_SEMIHOST) $(CPP_FLAGS) -print-multi-directory -g -T ../../ldscripts/microbit.ld -o hello.elf $^ | grep -v "_exn_" | ||
$(BIN_PATH)/clang++ $(MICROBIT_TARGET) $(CRT_SEMIHOST) $(CPP_FLAGS) -g -T ../../ldscripts/microbit.ld -o hello.elf $^ | ||
$(BIN_PATH)/llvm-objcopy -O ihex hello.elf hello.hex | ||
|
||
hello-exn.hex: hello-exn.cpp | ||
$(BIN_PATH)/clang++ $(MICROBIT_TARGET) $(CRT_SEMIHOST) -print-multi-directory -g -T ../../ldscripts/microbit.ld -o hello.elf $^ | grep "_exn_" | ||
$(BIN_PATH)/clang++ $(MICROBIT_TARGET) $(CRT_SEMIHOST) -g -T ../../ldscripts/microbit.ld -o hello-exn.elf $^ | ||
$(BIN_PATH)/llvm-objcopy -O ihex hello-exn.elf hello-exn.hex | ||
|
||
run: hello.hex hello-exn.hex | ||
qemu-system-arm -M microbit -semihosting -nographic -device loader,file=hello.hex | ||
qemu-system-arm -M microbit -semihosting -nographic -device loader,file=hello-exn.hex 2>&1 | grep "caught" | ||
|
||
clean: | ||
rm -f *.elf *.hex | ||
|
||
.PHONY: clean run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Bare-metal semihosting exceptions sample | ||
|
||
This sample shows and tests that C++ exceptions and corresponding | ||
library variant selection work correctly. |
12 changes: 12 additions & 0 deletions
12
samples/src/cpp-baremetal-semihosting-exceptions/hello-exn.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <iostream> | ||
|
||
int main(void) { | ||
try { | ||
throw "error"; | ||
} catch(...) { | ||
std::cout << "Exception caught." << std::endl; | ||
return 0; | ||
} | ||
std::cout << "Exception skipped." << std::endl; | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
|
||
int main(void) { | ||
std::cout << "No exceptions." << std::endl; | ||
return 0; | ||
} |