rockowitz / ddcui

Graphical user interface for ddcutil - control monitor settings
http://www.ddcutil.com
GNU General Public License v2.0
147 stars 2 forks source link

ddcui 0.2.0 segmentation fault immediately after launch #34

Closed reagentoo closed 2 years ago

reagentoo commented 2 years ago

My config: Linux Gentoo ~amd64 Gnome 41 + wayland

Please see backtrace:

GDB backtrace ``` $ gdb ddcui GNU gdb (Gentoo 11.1 vanilla) 11.1 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ddcui... Reading symbols from /usr/lib/debug//usr/bin/ddcui.debug... (gdb) (gdb) run Starting program: /usr/bin/ddcui [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7ffff3ef3640 (LWP 27860)] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. [New Thread 0x7ffff2c87640 (LWP 27861)] [New Thread 0x7ffff2486640 (LWP 27862)] [New Thread 0x7ffff1c85640 (LWP 27863)] [New Thread 0x7ffff1484640 (LWP 27864)] Thread 1 "ddcui" received signal SIGSEGV, Segmentation fault. 0x000055555559e5f4 in fprintf (__fmt=0x5555555cac60 "ddcui option parsing failed: %s\n", __stream=) at /usr/include/bits/stdio2.h:105 105 return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt, (gdb) bt full #0 0x000055555559e5f4 in fprintf (__fmt=0x5555555cac60 "ddcui option parsing failed: %s\n", __stream=) at /usr/include/bits/stdio2.h:105 No locals. #1 parse_ddcui_command (argc=, argv=0x555555670f10) at /var/tmp/portage/app-misc/ddcui-9999/work/ddcui-9999/src/cmdline/ddcui_cmd_parser.c:312 debug = false parsed_cmd = 0x555555670f30 ddc_flag = 0 report_freed_excp_flag = 0 timestamp_trace_flag = 0 thread_id_trace_flag = 0 version_flag = 0 show_styles_flag = 0 show_active_style_flag = 0 less_sleep_true_set = 0 less_sleep_false_set = 0 use_latest_nc_values_true_set = 0 hidpi_flag = 0 cmd_and_args = 0x0 trace_classes = 0x0 trace_filenames = 0x0 trace_functions = 0x0 sleep_multiplier_work = 0x0 nc_values_source_work = 0x0 feature_set_work = 0x0 custom_feature_set_work = 0x0 control_key_required = 0 show_unsupported_features = 0 only_capabilities_true_set = 0 only_capabilities_false_set = 0 all_capabilities_true_set = 0 all_capabilities_false_set = 0 debug_parse = 0 parse_only = 0 f1_flag = 0 f2_flag = 0 f3_flag = 0 f4_flag = 0 f5_flag = 0 f6_flag = 0 public_option_entries = {{long_name = 0x5555555ca715 "require-control-key", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd448, description = 0x5555555caab8 "Control key must be pressed to move slider", arg_description = 0x0}, { long_name = 0x5555555ca729 "nc-values-source", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x7fffffffd490, description = 0x5555555ca73a "Initial NC values source", arg_description = 0x5555555ca753 "MMCS|Capabilities|Both"}, {long_name = 0x5555555ca79c "feature-set", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x7fffffffd498, description = 0x5555555ca76a "Feature set selection", arg_description = 0x5555555caae8 "MMCS|Capabilities|Manufacturer|Color|Scan"}, { long_name = 0x5555555ca780 "use-latest-nc-values", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd440, description = 0x5555555cab18 "Use NC values from the latest MCCS version", arg_description = 0x0}, {long_name = 0x5555555ca795 "custom-feature-set", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x7fffffffd4a0, description = 0x5555555ca7a8 "User feature set definition", arg_description = 0x5555555cab48 "comma separated list of feature codes"}, {long_name = 0x5555555ca7c4 "show-unsupported", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd44c, description = 0x5555555ca7d5 "Show unsupported features", arg_description = 0x0}, { long_name = 0x5555555ca7ef "only-capabilities", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd450, description = 0x5555555cab70 "Include only values in capabilities", arg_description = 0x0}, { long_name = 0x5555555ca801 "all-capabilities", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd454, description = 0x5555555cab98 "Include all values in capabilities", arg_description = 0x0}, { long_name = 0x5555555ca812 "model", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING, arg_data = 0x555555670f70, --Type for more, q to quit, c to continue without paging-- description = 0x5555555ca818 "Model of default display", arg_description = 0x0}, {long_name = 0x5555555ca831 "stats", short_name = 115 's', flags = 32, arg = G_OPTION_ARG_CALLBACK, arg_data = 0x55555559d680 , description = 0x5555555ca837 "Show performance statistics", arg_description = 0x5555555ca853 "TRIES|ERRORS|CALLS|ALL"}, { long_name = 0x5555555ca86a "ddc", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd424, description = 0x5555555cabc0 "Report DDC protocol and data errors", arg_description = 0x0}, { long_name = 0x5555555ca879 "styles", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd438, description = 0x5555555ca86e "List known styles", arg_description = 0x0}, {long_name = 0x5555555ca880 "show-style", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd43c, description = 0x5555555ca88b "Show active style", arg_description = 0x0}, {long_name = 0x5555555ca89d "version", short_name = 86 'V', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd434, description = 0x5555555ca8a5 "Show version information", arg_description = 0x0}, {long_name = 0x0, short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x0, description = 0x0, arg_description = 0x0}} development_options = {{long_name = 0x5555555ca8be "excp", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd428, description = 0x5555555ca8c3 "Report freed exceptions", arg_description = 0x0}, { long_name = 0x5555555ca8db "trace", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING_ARRAY, arg_data = 0x7fffffffd478, description = 0x5555555ca8e1 "Trace a group", arg_description = 0x5555555ca8ef "trace group name"}, {long_name = 0x5555555ca900 "trcfunc", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING_ARRAY, arg_data = 0x7fffffffd488, description = 0x5555555ca908 "Trace a function", arg_description = 0x5555555ca919 "function name"}, {long_name = 0x5555555ca927 "trcfile", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_STRING_ARRAY, arg_data = 0x7fffffffd480, description = 0x5555555ca92f "Trace a file", arg_description = 0x5555555ca93c "file name"}, {long_name = 0x5555555ca946 "timestamp", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd42c, description = 0x5555555cabe8 "Prepend trace msgs with elapsed time", arg_description = 0x0}, {long_name = 0x5555555cfaca "ts", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd42c, description = 0x5555555cabe8 "Prepend trace msgs with elapsed time", arg_description = 0x0}, { long_name = 0x5555555ca950 "thread-id", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd430, description = 0x5555555cac10 "Prepend trace msgs with thread id", arg_description = 0x0}, { long_name = 0x5555555ca95a "tid", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd430, description = 0x5555555cac10 "Prepend trace msgs with thread id", arg_description = 0x0}, { long_name = 0x5555555ca95e "debug-parse", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd458, description = 0x5555555ca96a "Show parse result", arg_description = 0x0}, { long_name = 0x5555555ca97c "parse-only", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd45c, description = 0x5555555ca987 "Exit after parsing", arg_description = 0x0}, { long_name = 0x5555555ca99a "hidpi", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd444, description = 0x5555555ca9a0 "Test hidpi code", arg_description = 0x0}, {long_name = 0x5555555ca9b0 "f1", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd460, description = 0x5555555ca9b3 "Special flag 1", arg_description = 0x0}, {long_name = 0x5555555ca9c2 "f2", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd464, description = 0x5555555ca9c5 "Special flag 2", arg_description = 0x0}, {long_name = 0x5555555ca9d4 "f3", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd468, description = 0x5555555ca9d7 "Special flag 3", arg_description = 0x0}, {long_name = 0x5555555ca9e6 "f4", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd46c, description = 0x5555555ca9e9 "Special flag 4", arg_description = 0x0}, {long_name = 0x5555555ca9f8 "f5", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd470, description = 0x5555555ca9fb "Special flag 5", arg_description = 0x0}, {long_name = 0x5555555caa0a "f6", short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x7fffffffd474, description = 0x5555555caa0d "Special flag 6", arg_description = 0x0}, {long_name = 0x0, short_name = 0 '\000', flags = 0, arg = G_OPTION_ARG_NONE, arg_data = 0x0, description = 0x0, arg_description = 0x0}} final_options = {{long_name = , short_name = , flags = , arg = G_OPTION_ARG_STRING_ARRAY, arg_data = , description = , arg_description = }, {long_name = , short_name = , flags = , arg = , arg_data = , description = , arg_description = }} development_option_group = 0x555555670fb0 error = 0x0 context = 0x555555668b30 help_description = mangleable_argv = 0x555555670f10 ok = ndx = s = #2 0x000055555558c89c in main (argc=, argv=) at /var/tmp/portage/app-misc/ddcui-9999/work/ddcui-9999/src/main/main.cpp:311 --Type for more, q to quit, c to continue without paging-- debug = false __func__ = application = errmsgs = 0x55555562f360 new_argv = 0x555555670f10 new_argc = 1 combined_config_file_options = 0x0 config_fn = 0x0 apply_config_rc = 0 parsed_cmd = globalState = w = { = {}, static staticMetaObject = {d = {superdata = { direct = 0x7ffff7f87f20 }, stringdata = 0x5555555c49e0 , data = 0x5555555c4660 , static_metacall = 0x55555558e6a0 , relatedMetaObjects = 0x0, extradata = 0x0}}, _uid = 0x0, _feature_selector = 0x7ffff6891b0a, _msgBoxQueue = 0x0, _msgBoxThread = 0x1, _serialMsgBox = 0x5b0000006e, _cls = 0x28 , _ui = 0x5b0000006e, _dlist = 0xffffffff00000003, _curDisplayIndex = 36, _curView = MainWindow::NoView, _toolbarDisplayCB = 0x7ffff69e6c60, _otherOptionsState = 0x0, _uiOptionsState = 0x3000000003, _monitors = {d = 0x0}, _feature_list_id = DDCA_SUBSET_UNSET, _vcp_threads = {d = 0x0}, _loadingMsgBox = 0x770000007c, _fsd = 0x5b0000006e, _ood = 0x6} mainStatus = (gdb) ```
rockowitz commented 2 years ago

What are the command line arguments passed to ddcui? Is there a ddcutilrc configuration file - if so, please post its contents.

What version of glib are you using?

reagentoo commented 2 years ago

What are the command line arguments passed to ddcui?

Just ddcui.

Is there a ddcutilrc configuration file - if so, please post its contents.

No any custom config files.

What version of glib are you using?

dev-libs/glib-2.70.2

// May be the problem is in missing i2c group for user.

rockowitz commented 2 years ago

It looks like the segfault occurs after glib function g_option_parse_strv() fails without setting an error message. The reason I asked about your glib version is that the argument requirements for this function were relaxed as of glib 2.62.

Your command line arguments are trivial, and I can't reproduce the failure here. It's as if some software components are out of sync. What version of libddcutil are you running?

Are you able to build ddcui from the source here on GitHub? The latest 0.2.1-dev branch contains enhanced build and trace options, and also a workaround for the segfault, though I suspect that will only move the locus of the failure.

To build ddcui, use the command:
cmake --S <your source directory> -B <your build directory> -DCMAKE_BUILD_TYPE=Debug

When running ddcui, setting environment variable DDCUTIL_DEBUG_PARSE=1 enables debug code in the parser,
e.g. DDCUTIL_DEBUG_PARSE=1 <directory path>/ddcui or even better: DDCUTIL_DEBUG_PARSE=1 valgrind <directory path>/ddcui

And of course, submit relevant output as attachments of some sort. Thank you.

reagentoo commented 2 years ago

What version of libddcutil are you running?

app-misc/ddcutil-1.2.1

When running ddcui, setting environment variable DDCUTIL_DEBUG_PARSE=1 enables debug code in the parser, e.g. DDCUTIL_DEBUG_PARSE=1 /ddcui or even better: DDCUTIL_DEBUG_PARSE=1 valgrind /ddcui

Currently run w/o sigsegv. Please see attached log:

DDCUTIL_DEBUG_PARSE=1 ./ddcui ``` $ DDCUTIL_DEBUG_PARSE=1 ./ddcui Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway. (parse_ddcui_command) Starting argc=1 argv[0] = |./ddcui| (parse_ddcui_command) prgname = ddcui, application_name = ddcui (parse_ddcui_command) Before g_option_context_parse_strv(), mangleable_argv: Null_Terminated_String_Array at 0x564ac0296d20: 0x564ac0296d00: |./ddcui| Total entries: 1 (parse_ddcui_command) Freeing mangleable_argv=0x564ac0296d20: Null_Terminated_String_Array at 0x564ac0296d20: 0x564ac0296d00: |./ddcui| Total entries: 1 (dbgrpt_parsed_ddcui_cmd) Parsed_Cmd at 0x564ac0370640 stats: 0x00000000 traced_groups 0x00000000 traced_functions: none traced_files: none report_freed_exceptions: false display ddc errors: false timestamp prefix: false thread_id prefix: false show styles: false show active style: false require control key: false initial view: VIEW_UNSET default feature set: FS_UNSET custom feature set: NC values source: NC_VALUES_SOURCE_UNSET Force Latest NC Value Names:false include all capabilities features: not set include_only capabilities features: not set initial model: (null) initial bus number: -1 hidpi: false (parse_ddcui_command) ddcui parser returning: 0x564ac0370640 qt.qpa.wayland: Wayland does not support QWindow::requestActivate() qt.qpa.wayland: Wayland does not support QWindow::requestActivate() qt.qpa.wayland: Wayland does not support QWindow::requestActivate() qt.qpa.wayland: Wayland does not support QWindow::requestActivate() ```
reagentoo commented 2 years ago

@rockowitz Is there any other info needed?

rockowitz commented 2 years ago

I've just fixed a segfault in the tracing code of API function ddca_display_refs(), but you apparently haven't enabled libddcutil tracing that wouldn't apply to you.

What I need is output that pinpoints the locus of error. The dgb output does not do the trick. Please build libddcutil from the 1.2.2-dev branch. Do not optimize out debug information. Also build ddcui with debug information, using the cmake command above. Then run

DDCUTIL_DEBUG_PARSE=1 valgrind <directory path>/ddcui --trace all

The output will be insanely voluminous, but valgrind along with ddcutil tracing should be able to identify the location of the failure.

rockowitz commented 2 years ago

I have installed gentoo derivative Calculate Linux, and built ddcutil and ddcui. It appears that the segfault you are seeing is a mismatch between libddcutil and ddcui.

If I install ddcutil using emerge, the source version obtained from app-misc/dccutil is 0.9.9. This is ancient, and a segfault is to be expected if its libddcutil is used by any recent version of ddcui. If I explicitly request version 1.2.1, emerge fails with an error message indicating a problem with the repository configuration. I'll leave it to you to resolve this problem.

The mismatch was not caught at ddcui build time because of a bug in CMakeLists.txt. The build configuration file had not been updated to require at least ddcutil 1.2.0. This has been fixed in the current ddcui development branch, 0.2.1-dev, which requires the current ddcutil devlopment branch 1.2.2 -dev.

AndrewAmmerlaan commented 2 years ago

If I install ddcutil using emerge, the source version obtained from app-misc/dccutil is 0.9.9. This is ancient, and a segfault is to be expected if its libddcutil is used by any recent version of ddcui. If I explicitly request version 1.2.1, emerge fails with an error message indicating a problem with the repository configuration. I'll leave it to you to resolve this problem.

app-misc/ddcui-0.1.2-r1 explicitly depends on >=app-misc/ddcutil-0.9.9:0/3 (that is slot 0, subslot 3), app-misc/ddcui-0.2.0 on the other hand depends on >=app-misc/ddcutil-1.2.0:0/4 (slot 0, subslot 4). This means that ddcui-0.1.2 will pull in ddcutil-0.9.9 (the version which has subslot 3), this combination works. Ddcui-0.2.0, will pull in ddcutil-1.2.1 (the version which has subslot 4), this combination results in the segfault. Installing ddcui-0.2.0 with ddcutil-0.9.9 is explicitly prohibited by the package manager, this is on purpose because it will result in compile failure.

The 'error message' you're seeing is intentional. It indicates that app-misc/ddcui-0.2.0 is not keyworded for your architecture. I specifically omitted the keywords on ddcui-0.2.0 because of this segfault problem, I don't want users upgrading to this version until we have fixed the problem. Unfortunately, the side effect is that ddcutil-0.9.9 is pulled in, which is indeed ancient.

In short, the repository is the way it is because of this issue, it is not the cause of it. I'll see about getting you a proper backtrace later today.

AndrewAmmerlaan commented 2 years ago

I'll see about getting you a proper backtrace later today.

Here's the output of DDCUTIL_DEBUG_PARSE=1 valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/log ddcui --trace=all: log.txt

And here's the output of gdb:

Reading symbols from ddcui...
Reading symbols from /usr/lib/debug//usr/bin/ddcui.debug...
[New LWP 28108]
[New LWP 28114]
[New LWP 28115]
[New LWP 28109]
[New LWP 28116]
[New LWP 28118]
[New LWP 28110]
[New LWP 28117]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
--Type <RET> for more, q to quit, c to continue without paging--c
Core was generated by `ddcui --trace=all'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000055578492c53f in fprintf (__fmt=0x555784958c60 "ddcui option parsing failed: %s\n", __stream=<optimized out>) at /usr/include/bits/stdio2.h:105

warning: Source file is more recent than executable.
105       return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
[Current thread is 1 (Thread 0x7f850801e780 (LWP 28108))]

The following packages have been compiled with debug flags and symbols:

app-misc/ddcutil debug
app-misc/ddcui debug
sys-libs/glibc debug
dev-qt/qtcore debug
dev-qt/qtgui debug
dev-qt/qtdbus debug
dev-qt/qtdeclarative debug
dev-libs/glib debug
kde-plasma/breeze debug
media-libs/libglvnd debug
kde-frameworks/kconfig debug
sys-apps/dbus debug
kde-frameworks/kio debug
sys-fs/udev debug
x11-libs/libX11 debug
kde-plasma/plasma-integration debug
kde-frameworks/kbookmarks debug
kde-frameworks/kitemviews debug
kde-frameworks/kdbusaddons debug
kde-frameworks/kcoreaddons debug
kde-frameworks/kwidgetsaddons debug 
kde-frameworks/kcompletion debug
kde-frameworks/kjobwidgets debug
kde-frameworks/kglobalaccel debug
kde-frameworks/kguiaddons debug
kde-frameworks/kxmlgui debug
kde-frameworks/kwindowsystem debug
kde-frameworks/knotifications debug
kde-frameworks/kiconthemes debug
kde-frameworks/kcodecs debug
kde-frameworks/kitemviews debug
kde-frameworks/ki18n debug
media-libs/phonon debug
kde-frameworks/kauth debug
kde-frameworks/kconfigwidgets debug
x11-libs/libxcb debug
kde-frameworks/kdbusaddons debug
kde-frameworks/solid debug
kde-frameworks/kcrash debug
kde-frameworks/frameworkintegration debug
dev-qt/qtquickcontrols2 debug
dev-qt/qtquickcontrols debug
dev-qt/qtwayland debug
dev-qt/qtwidgets debug
x11-libs/libxkbcommon debug
kde-frameworks/kservice debug
dev-qt/qtprintsupport debug
kde-frameworks/kwayland debug
rockowitz commented 2 years ago

The segfault reported has been fixed in ddcui branch 0.2.1-dev. A similar fix has been applied in ddcutil branch 1.2.2-dev. The fixes allow for the possibility that glib function g_option_context_parse_strv() fails without setting an error message. That g_option_context_parse_strv() fails in this way is pathological, suggesting that the fixes will only move the locus of failure. Since both ddcutil and ddcui build and execute successfully on my copy of Calculate Linux, I continue to suspect a configuration problem of some sort.

AndrewAmmerlaan commented 2 years ago

Ddcui version 0.2.1 with ddcutil version 1.2.2 works flawlessly, no more segfaults :+1:

I think we can close this issue