From fd5172e1f35d7cacb2a191ad86bcdc88810100c7 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 6 Apr 2025 11:40:36 +0200 Subject: [PATCH] base/output.h: make Alloc_error printable Issue #5245 --- repos/base/include/base/allocator.h | 17 ----------------- repos/base/include/base/output.h | 6 ++++++ repos/base/lib/symbols/ld | 1 + repos/base/recipes/pkg/test-log/runtime | 1 + repos/base/run/log.run | 1 + repos/base/src/lib/base/output.cc | 13 +++++++++++++ repos/base/src/test/log/main.cc | 1 + 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/repos/base/include/base/allocator.h b/repos/base/include/base/allocator.h index 9c5b9ae1a8..0ea1434e88 100644 --- a/repos/base/include/base/allocator.h +++ b/repos/base/include/base/allocator.h @@ -305,23 +305,6 @@ void Genode::destroy(auto && dealloc, T *obj) namespace Genode { - void static inline print(Output &out, Allocator::Alloc_error error) - { - using Error = Allocator::Alloc_error; - - auto name = [] (Error error) - { - switch (error) { - case Error::OUT_OF_RAM: return "OUT_OF_RAM"; - case Error::OUT_OF_CAPS: return "OUT_OF_CAPS"; - case Error::DENIED: return "DENIED"; - } - return ""; - }; - - Genode::print(out, name(error)); - } - void static inline print(Output &out, Allocator::Alloc_result result) { result.with_result( diff --git a/repos/base/include/base/output.h b/repos/base/include/base/output.h index ee2c7237d7..6219b423b4 100644 --- a/repos/base/include/base/output.h +++ b/repos/base/include/base/output.h @@ -15,6 +15,7 @@ #define _INCLUDE__BASE__OUTPUT_H_ #include +#include #include namespace Genode { struct Output; } @@ -210,6 +211,11 @@ namespace Genode { void print(Output &output) const { output.out_char(c); } }; + /** + * Print error codes defined at base/error.h + */ + void print(Output &, Alloc_error); + /** * Print information about object 'obj' * diff --git a/repos/base/lib/symbols/ld b/repos/base/lib/symbols/ld index 4cc6135ab8..4e0b7f8abd 100644 --- a/repos/base/lib/symbols/ld +++ b/repos/base/lib/symbols/ld @@ -244,6 +244,7 @@ _ZN6Genode5Trace6Logger17_evaluate_controlEv T _ZN6Genode5Trace6Logger3logEPKcm T _ZN6Genode5Trace6LoggerC1Ev T _ZN6Genode5Trace6LoggerC2Ev T +_ZN6Genode5printERNS_6OutputENS_11Alloc_errorE T _ZN6Genode5printERNS_6OutputEPKc T _ZN6Genode5printERNS_6OutputEPKv T _ZN6Genode5printERNS_6OutputEd T diff --git a/repos/base/recipes/pkg/test-log/runtime b/repos/base/recipes/pkg/test-log/runtime index 30942261eb..cf7ff48d08 100644 --- a/repos/base/recipes/pkg/test-log/runtime +++ b/repos/base/recipes/pkg/test-log/runtime @@ -8,6 +8,7 @@ [init -> test-log] invalid hex range: [f8,08) (overflow!) [init -> test-log] negative hex char: 0xfe [init -> test-log] positive hex char: 0x02 + [init -> test-log] Alloc_error value: OUT_OF_RAM [init -> test-log] floating point: 1.70 [init -> test-log] multiarg string: "parent -> child.7" [init -> test-log] String(Hex(3)): 0x3 diff --git a/repos/base/run/log.run b/repos/base/run/log.run index 9419d8f4e1..f46bd08056 100644 --- a/repos/base/run/log.run +++ b/repos/base/run/log.run @@ -33,6 +33,7 @@ compare_output_to { [init -> test-log] invalid hex range: [f8,08) (overflow!) [init -> test-log] negative hex char: 0xfe [init -> test-log] positive hex char: 0x02 +[init -> test-log] Alloc_error value: OUT_OF_RAM [init -> test-log] floating point: 1.70 [init -> test-log] multiarg string: "parent -> child.7" [init -> test-log] String(Hex(3)): 0x3 diff --git a/repos/base/src/lib/base/output.cc b/repos/base/src/lib/base/output.cc index 1887b78432..e7d6fef878 100644 --- a/repos/base/src/lib/base/output.cc +++ b/repos/base/src/lib/base/output.cc @@ -100,3 +100,16 @@ void Genode::Hex::print(Output &output) const [&] (char c) { output.out_char(c); }); } + +void Genode::print(Output &out, Alloc_error e) +{ + auto name = [] (Alloc_error e) + { + switch (e) { + case Alloc_error::OUT_OF_RAM: return "OUT_OF_RAM"; + case Alloc_error::OUT_OF_CAPS: return "OUT_OF_CAPS"; + case Alloc_error::DENIED: return "DENIED"; } + return ""; + }; + print(out, name(e)); +} diff --git a/repos/base/src/test/log/main.cc b/repos/base/src/test/log/main.cc index c3a4d97328..14c9eade1f 100644 --- a/repos/base/src/test/log/main.cc +++ b/repos/base/src/test/log/main.cc @@ -27,6 +27,7 @@ void Component::construct(Genode::Env &env) log("invalid hex range: ", Hex_range(0xf8, 0x10)); log("negative hex char: ", Hex((char)-2LL, Hex::PREFIX, Hex::PAD)); log("positive hex char: ", Hex((char) 2LL, Hex::PREFIX, Hex::PAD)); + log("Alloc_error value: ", Alloc_error::OUT_OF_RAM); log("floating point: ", 1700.0 / 1000);