emulator/vhci: Add debug messages to error paths
Luiz Augusto von Dentz
maintainerPATCH 1/4 emulator/vhci: Add debug messages to error paths
From: Luiz Augusto von Dentz <[email protected]>
Add debug_callback, debug_destroy and debug_data fields to struct vhci so vhci_set_debug stores the callback locally in addition to passing it to btdev. Introduce a variadic vhci_debug() helper using util_debug_va and add debug messages to the following error paths:
- vhci_write_callback: failed io_send
- vhci_read_callback: failed read
- vhci_debugfs_write: failed open and failed write
--- emulator/vhci.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-)
emulator/vhci.c +36 -4
@@ -19,6 +19,7 @@#include <unistd.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> #include <sys/uio.h> #include <fcntl.h> #include <unistd.h>
@@ -29,6 +30,7 @@#include "bluetooth/hci.h" #include "src/shared/io.h" +#include "src/shared/util.h" #include "monitor/bt.h" #include "btdev.h" #include "vhci.h"
@@ -41,8 +43,23 @@ struct vhci {uint16_t index;struct io *io;struct btdev *btdev; +vhci_debug_func_t debug_callback; +vhci_destroy_func_t debug_destroy; +void *debug_data; }; +static void vhci_debug (struct vhci *vhci,const char *format, ...) +{ +va_list ap; + +if (!vhci || !format || !vhci->debug_callback) +return ; + +va_start (ap, format); +util_debug_va (vhci->debug_callback, vhci->debug_data, format, ap); +va_end (ap); +} +static void vhci_destroy (void *user_data) {struct vhci *vhci = user_data;
@@ -61,7 +78,7 @@ static void vhci_write_callback(const struct iovec *iov, int iovlen, written =io_send (vhci->io, iov, iovlen);if (written <0 ) -return ; +vhci_debug (vhci,"Failed to write: %s" ,strerror (-written)); }static bool vhci_read_callback (struct io *io,void *user_data)
@@ -72,8 +89,10 @@ static bool vhci_read_callback(struct io *io, void *user_data)ssize_t len; len =read (fd, buf,sizeof (buf)); -if (len <1 ) +if (len <1 ) { +vhci_debug (vhci,"Failed to read: %s" ,strerror (errno));return false; + }btdev_receive_h4 (vhci->btdev, buf, len);
@@ -86,6 +105,13 @@ bool vhci_set_debug(struct vhci *vhci, vhci_debug_func_t callback,if (!vhci)return false; +if (vhci->debug_destroy) + vhci->debug_destroy (vhci->debug_data); + + vhci->debug_callback = callback; + vhci->debug_destroy = destroy; + vhci->debug_data = user_data; +return btdev_set_debug (vhci->btdev, callback, user_data, destroy); }
@@ -205,14 +231,20 @@ static int vhci_debugfs_write(struct vhci *vhci, char *option, const void *data,sprintf (path,DEBUGFS_PATH "/hci%d/%s" , vhci->index, option); fd =open (path,O_RDWR ); -if (fd <0 ) +if (fd <0 ) { +vhci_debug (vhci,"Failed to open %s: %s" , path, +strerror (errno));return -errno; + } n =write (fd, data, len);if (n == len) err =0 ; -else +else { err = -errno; +vhci_debug (vhci,"Failed to write %s: %s" , option, +strerror (-err)); + }close (fd);
Signature · 1 line
2.53.0
Luiz Augusto von Dentz
maintainerPATCH 2/4 emulator/hciemu: Add debug messages to error paths
From: Luiz Augusto von Dentz <[email protected]>
Introduce a variadic hciemu_debug() helper using util_debug_va and add debug messages to the following error paths:
- create_vhci: failed to open vhci
- hciemu_client_new: failed to create btdev, bthost, or socketpair
--- emulator/hciemu.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
emulator/hciemu.c +20 -1
@@ -19,6 +19,7 @@#include <stdlib.h> #include <string.h> #include <stdbool.h> +#include <stdarg.h> #include <errno.h> #include <sys/socket.h> #include <sys/ioctl.h>
@@ -60,6 +61,18 @@ struct hciemu {unsigned int flush_id; }; +static void hciemu_debug (struct hciemu *hciemu,const char *format, ...) +{ +va_list ap; + +if (!hciemu || !format || !hciemu->debug_callback) +return ; + +va_start (ap, format); +util_debug_va (hciemu->debug_callback, hciemu->debug_data, format, ap); +va_end (ap); +} +struct hciemu_command_hook {hciemu_command_func_t function;void *user_data;
@@ -249,8 +262,10 @@ static bool create_vhci(struct hciemu *hciemu)struct vhci *vhci; vhci =vhci_open (hciemu->btdev_type); -if (!vhci) +if (!vhci) { +hciemu_debug (hciemu,"Failed to open vhci" );return false; + }btdev_set_command_handler (vhci_get_btdev (vhci), central_command_callback, hciemu);
@@ -343,12 +358,14 @@ static struct hciemu_client *hciemu_client_new(struct hciemu *hciemu, client->dev =btdev_create (hciemu->btdev_type, id++);if (!client->dev) { +hciemu_debug (hciemu,"Failed to create btdev" );free (client);return NULL ; } client->host =bthost_create ();if (!client->host) { +hciemu_debug (hciemu,"Failed to create bthost" );btdev_destroy (client->dev);free (client);return NULL ;
@@ -358,6 +375,8 @@ static struct hciemu_client *hciemu_client_new(struct hciemu *hciemu,if (socketpair (AF_UNIX ,SOCK_SEQPACKET |SOCK_NONBLOCK |SOCK_CLOEXEC ,0 , sv) <0 ) { +hciemu_debug (hciemu,"Failed to create socketpair: %s" , +strerror (errno));bthost_destroy (client->host);btdev_destroy (client->dev);return NULL ;
Signature · 1 line
2.53.0
Luiz Augusto von Dentz
maintainerPATCH 3/4 tools/gap-tester: Enable hciemu debug output
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Add print_debug callback and call hciemu_set_debug when debug output is enabled so that hciemu error paths are visible during test runs.
--- tools/gap-tester.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/gap-tester.c +10 -0
@@ -23,11 +23,21 @@ static GDBusProxy *adapter_proxy = NULL;static struct hciemu *hciemu_stack =NULL ; +static void print_debug (const char *str,void *user_data) +{ +const char *prefix = user_data; + +tester_print ("%s%s" , prefix, str); +} +static void connect_handler (DBusConnection *connection,void *user_data) {tester_print ("Connected to daemon" ); hciemu_stack =hciemu_new (HCIEMU_TYPE_BREDRLE ); + +if (tester_use_debug ()) +hciemu_set_debug (hciemu_stack, print_debug,"hciemu: " ,NULL ); }static void disconnect_handler (DBusConnection *connection,void *user_data)
Signature · 1 line
2.53.0
Luiz Augusto von Dentz
maintainerPATCH 4/4 tools/userchan-tester: Enable hciemu debug output
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Call hciemu_set_debug when debug output is enabled so that hciemu error paths are visible during test runs.
--- tools/userchan-tester.c | 3 +++ 1 file changed, 3 insertions(+)
tools/userchan-tester.c +3 -0
@@ -158,6 +158,9 @@ static void read_index_list_callback(uint8_t status, uint16_t length,tester_pre_setup_failed (); } +if (tester_use_debug ()) +hciemu_set_debug (data->hciemu, mgmt_debug,"hciemu: " ,NULL ); +tester_print ("New hciemu instance created" ); }
Signature · 1 line
2.53.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1090123
---Test result---
Test Summary:
CheckPatch PASS 1.97 seconds GitLint PASS 1.46 seconds BuildEll PASS 19.86 seconds BluezMake PASS 611.29 seconds CheckSmatch PASS 322.85 seconds bluezmakeextell PASS 167.27 seconds IncrementalBuild PASS 612.35 seconds ScanBuild PASS 896.75 seconds
https://github.com/bluez/bluez/pull/2100
---
Regards,
Linux Bluetooth
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Tue, 5 May 2026 16:47:16 -0400 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
Add
debug_callback,debug_destroyanddebug_datafields to struct vhci sovhci_set_debugstores the callback locally in addition to passing it to btdev. Introduce a variadicvhci_debug()helper usingutil_debug_vaand add debug messages to the following error paths:[...]
Here is the summary with links:
- [BlueZ,v1,1/4] emulator/vhci: Add debug messages to error paths
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d0d42d034f9f - [BlueZ,v1,2/4] emulator/hciemu: Add debug messages to error paths https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d4c965eec4d3 - [BlueZ,v1,3/4] tools/gap-tester: Enable hciemu debug output https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=164941a6c145 - [BlueZ,v1,4/4] tools/userchan-tester: Enable hciemu debug output https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e51115ccd4df
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html