Add std:string overload for Debug (#255)
Add an overload in debug for std:string based on the pattern for
std::string_view
diff --git a/sdk/include/debug.hh b/sdk/include/debug.hh
index 21fb6b8..af0732e 100644
--- a/sdk/include/debug.hh
+++ b/sdk/include/debug.hh
@@ -285,6 +285,19 @@
};
/**
+ * String view specialisation, use the C string handler.
+ */
+template<>
+struct DebugFormatArgumentAdaptor<std::string>
+{
+ __always_inline static DebugFormatArgument construct(std::string &value)
+ {
+ return DebugFormatArgumentAdaptor<const char *>::construct(
+ value.c_str());
+ }
+};
+
+/**
* Enum specialisation, prints the enum as a string and then the numeric value.
*
* This specialisation uses the generic printing facility in the library call
diff --git a/tests/test-runner.cc b/tests/test-runner.cc
index 5ae2963..2227633 100644
--- a/tests/test-runner.cc
+++ b/tests/test-runner.cc
@@ -4,8 +4,10 @@
#include "tests.hh"
#include <compartment.h>
#include <simulator.h>
+#include <string>
using namespace CHERI;
+using namespace std::string_literals;
namespace
{
@@ -104,10 +106,10 @@
0x123456789012345ULL);
const char *testString = "Hello, world! with some trailing characters";
// Make sure that we don't print the trailing characters
- debug_log("Trying to print string: {}", std::string_view{testString, 13});
- std::string hi = "Hello world";
- debug_log("Trying to print std::string: {}", hi.c_str());
-
+ debug_log("Trying to print std::string_view: {}",
+ std::string_view{testString, 13});
+ const std::string S = "I am a walrus"s;
+ debug_log("Trying to print std::string: {}", S);
run_timed("All tests", []() {
run_timed("Debug helpers (C++)", test_debug_cxx);
run_timed("Debug helpers (C)", test_debug_c);