Skip to content

Commit 6096387

Browse files
Merge pull request #59 from Reim-developer/dev
Improve debug
2 parents 4908c3d + 13a582f commit 6096387

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/front_end/main_window_preload.cxx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
#include <qpalette.h>
88

99
#include <memory>
10-
#include <sstream>
10+
#include <print>
1111
#include <string>
1212

1313
#include "../ffi/namespace/include/config.hxx"
1414
#include "../ffi/namespace/include/utils.hxx"
1515
#include "include/theme_manager.hxx"
1616

1717
#if defined(LAZY_DEBUG)
18-
#include <iostream>
19-
using std::cout;
18+
#include <format>
19+
20+
#include "../front_end_utils/include/utils.hxx"
21+
using Lazyboard::front_end_utils::dump_ptr_address;
22+
using std::println;
2023
#endif
2124

2225
#include "../front_end_utils/include/error_types.hxx"
@@ -25,9 +28,9 @@ using std::cout;
2528
using Lazyboard::front_end::MainWindowPreload;
2629
using Self = MainWindowPreload;
2730

31+
using std::format;
2832
using std::make_unique;
2933
using std::string;
30-
using std::stringstream;
3134
using namespace Lazyboard::ffi;
3235
using Lazyboard::front_end_utils::error_dialog_show;
3336
using Lazyboard::front_end_utils::ErrorTypes;
@@ -96,11 +99,7 @@ void Self::on_read_exists_cfg_error(RawReadAppConfigStatus status,
9699

97100
string Self::application_config() {
98101
auto config_dir_raw = ffi::config_dir();
99-
100-
stringstream string_stream;
101-
string_stream << config_dir_raw << "/Lazyboard"
102-
<< "/settings.toml";
103-
string config_path = string_stream.str();
102+
string config_path = format("{}/Lazyboard/settings.toml", config_dir_raw);
104103

105104
ffi::free_c_str(config_dir_raw);
106105
return config_path;
@@ -116,14 +115,14 @@ void Self::create_default_config(QMainWindow *main_window) {
116115

117116
// clang-format off
118117
#if defined(LAZY_DEBUG)
119-
cout << "[DEBUG] " << "Config path not found, generate at: " << config_path << "\n";
118+
println("[DEBUG] Config path not found, generate at: {}", config_path);
120119
#endif
121120

122121
return;
123122
}
124123

125124
#if defined(LAZY_DEBUG)
126-
cout << "[DEBUG] " << "Found config path at: " << config_path << "\n";
125+
println("[DEBUG] Found config path at: {}", config_path);
127126
#endif // clang-format on
128127
}
129128

@@ -136,4 +135,12 @@ void Self::read_if_exists_config(QMainWindow *main_window) {
136135
this->on_read_exists_cfg_error(status, main_window);
137136

138137
theme_manager->set_main_window_theme(main_window, raw_app_config.get());
138+
139+
// clang-format off
140+
#if defined (LAZY_DEBUG)
141+
dump_ptr_address(raw_app_config.get());
142+
dump_ptr_address(theme_manager.get());
143+
dump_ptr_address(main_window);
144+
145+
#endif // clang-format on
139146
}

src/front_end_utils/include/utils.hxx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ using std::is_same_v;
2121
using std::stringstream;
2222
using std::vector;
2323

24+
#if defined(LAZY_DEBUG)
25+
#include <print>
26+
#include <source_location>
27+
using std::println;
28+
using std::source_location;
29+
#endif
30+
2431
namespace Lazyboard::front_end_utils {
2532

2633
template <typename T>
@@ -41,7 +48,8 @@ inline constexpr bool is_valid_hex_color(const Args&... args) noexcept {
4148
...);
4249
}
4350

44-
inline QIcon image_from_bytes(const initializer_list<uint8_t>& data) noexcept {
51+
using init_list = initializer_list<uint8_t>;
52+
inline QIcon image_from_bytes(const init_list& data) noexcept {
4553
QByteArray bytes_array;
4654
bytes_array.reserve(static_cast<int>(data.size()));
4755

@@ -65,6 +73,23 @@ inline void error_dialog_show(QWidget* parent,
6573
abort();
6674
}
6775

76+
#if defined(LAZY_DEBUG)
77+
using src_loc = source_location;
78+
template <typename T>
79+
inline void dump_ptr_address(T* t,
80+
const src_loc& location = src_loc::current()) {
81+
auto green = "\x1b[32m";
82+
auto white = "\x1b[37m";
83+
84+
auto file_name = location.file_name();
85+
auto file_line = location.line();
86+
87+
println("{}[MEMORY_DEBUG]{} File: {}", green, white, file_name);
88+
println("{}[MEMORY_DEBUG]{} Line: {}", green, white, file_line);
89+
println("{}[MEMORY_DEBUG]{} {}", green, white, static_cast<void*>(t));
90+
}
91+
#endif
92+
6893
} // namespace Lazyboard::front_end_utils
6994

7095
#endif

0 commit comments

Comments
 (0)