Debug QEMU/KVM with gdb via a serial port - linux

I tried to set-up QEMU/KVM to for GDB debuggin with a serial port and couldn't managed to make it work.
According to QEMU GDB documentation
If you want to specify which TCP port to use or to use something other
than TCP for the gdbstub connection, use the -gdb dev option instead
of -s.
Here are my attempts:
I. I looked at available tty devices and picked up the first one /dev/ttyS0
sudo qemu-system-x86_64 -gdb /dev/ttyS0 -S
In GDB I tried
(gdb) target remote /dev/ttyS0
get_tty_state failed: Input/output error
set_tty_state failed: Input/output error
Remote debugging using /dev/ttyS0
Remote communication error. Target disconnected.: Input/output error.
II. Create a chardev and pass it to -gdb option
sudo qemu-system-x86_64 -chardev serial,id=ser0,path=/dev/ttyS0 -gdb /dev/ttyS0 -S
GDB responds with the same error msg:
(gdb) target remote /dev/ttyS0
get_tty_state failed: Input/output error
set_tty_state failed: Input/output error
Remote debugging using /dev/ttyS0
Remote communication error. Target disconnected.: Input/output error.
III. Pass a chardev id to the -gdb option
$ sudo qemu-system-x86_64 -chardev serial,id=ser0,path=/dev/ttyS0 -gdb ser0 -S
qemu-system-x86_64: -gdb ser0: 'ser0' is not a valid char driver
This way QEMU does not start at all.
QUESTION: What is the correct way to set-up QEMU GDB debugging via a serial port?

Related

Cannot start J-Link GDB Server on Ubuntu

I am currently working on the ARM Cortex-M4 inside the NXP i.MX8M Mini.
I am able to compile a project for M4 on Eclipse IDE on an Ubuntu VM.
I would now like to debug on the M4 via a SEGGER Flasher ARM probe, still from Ubuntu.
My probe is well recognized by Ubuntu, and I can launch the J-Link GDB server by simply typing the command :
$ sudo ./JLinkGDBServerCLExe
However, if I type the same command without sudo, I get :
$ ./JLinkGDBServerCLExe
SEGGER J-Link GDB Server V7.58b Command Line Version
JLinkARM.dll V7.58b (DLL compiled Nov 16 2021 15:04:27)
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: yes
Generate logfile: off
Verify download: off
Init regs on start: off
Silent mode: off
Single run mode: off
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: Unspecified
Target interface: JTAG
Target interface speed: 4000kHz
Target endian: little
Connecting to J-Link...
Connecting to J-Link failed. Connected correctly?
GDBServer will be closed...
Shutting down...
Could not connect to J-Link.
Please check power, connection and settings.
My problem is that when I start eclipse, I get the same result as starting the GDB server without sudo.
It seems that this is a rights issue, how can I solve it?
As #KamilCuk said, the problem came from the udev rules.
So you just have to copy the rules provided by Segger with J-Link Software on the system:
$ sudo cp 99-jlink.rules /etc/udev/rules.d
Then you have to reboot the system:
$ reboot

dovecot unable to start due to address already in use

I upgraded my Linux kernel and dovecot failed to start with the following error messages:
Error: service(managesieve-login): listen(*, 4190) failed: Address already in use
Error: service(pop3-login): listen(*, 110) failed: Address already in use
Error: service(pop3-login): listen(*, 995) failed: Address already in use
Error: service(imap-login): listen(*, 143) failed: Address already in use
Error: service(imap-login): listen(*, 993) failed: Address already in use
Fatal: Failed to start listeners
Strangely enough, I couldn't find any process bounded to those port numbers. All commands below return nothing.
# netstat -tulpn | grep 110
# ss -tulpn |grep 110
# fuser 110/tcp
# lsof -i :110
I also tried to change the listen setting to my specific IP address and it still failed the same way.
Any idea how I can solve this problem? Here's my version info:
# uname -a
Linux ip-172-31-26-222 4.14.177-107.254.amzn1.x86_64 #1 SMP Thu May 7 18:30:14 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
# dovecot --version
2.2.36 (1f10bfa63)
Hi it looks like you are using AWS as I am. I recently updated via Yum as well. I noticed that a new package named 'portreserve' was also installed. I killed that process, left the /etc/dovecot/dovecot.conf as it was before and then started Dovecot successfully. I was also immediately able to reconnect my mail clients connection. I hope that helps you.
I also restarted the portreserve program since it seems useful to limit port access.

DPDK Error: "Cause: No Ethernet ports - bye"

The title is the last line of an error while trying to run a sample application of dpdk, named l2fwd. When I run the app by ./build/l2fwd -l 0-3 -n 4 -- -q 8 -p ffff but at last lines this error occurs:
EAL: Error - exiting with code: 1
Cause: No Ethernet ports - bye
According to dpdk documentation before running app I must execute a command: modprobe ixgbe max_vfs=2,2
I also have a problem with this command, but I'm not sure this is the main reason of failing app execution.
Error of modprobe command relates to ixgbe driver which I can't install it. The error after make of ixgbe is
cc1: error: code model kernel does not support PIC mode
Makefile:197: * * Aborting the build. *** This driver is not supported on kernel versions older than 2.4.0. Stop.
To you a NIC with DPDK we need to bind it to UIO or VFIO driver.
Please have a look at Binding and Unbinding Network Ports to/from the Kernel Modules in DPDK's getting started guide.

CentOS 7 USB. Connect to Wi-Fi using CLI only

I just installed CentOS 7 [Kernel 3.10.0-514] on my USB stick.
Operating system works fine but I had some problems with my Broadcom 43227 wireless card.
I downloaded driver, patched it, changed code a bit according to the instruction here: https://wiki.centos.org/HowTos/Laptops/Wireless/Broadcom and after many attempts it finally compilled and after loading the driver module into kernel led turned on.
Now I need to connect to my Wi-Fi.
What am I trying to do:
Get wireless interface name using iw dev:
phy#0
Interface wlp2s0
Scan to find WiFi Network using iw wlp2s0 scan | grep SSID
SSID: MyNetworkName
Generate a WPA/WPA2 configuration file using wpa_passphrase MyNetworkName >> /etc/wpa_supplicant.conf
MyNetworkPassword
Connect to WPA/WPA2 WiFi network using wpa_supplicant -B -D wext -i wlp2s0 -c /etc/wpa_supplicant.conf
Successfylly initialized wpa_supplicant
[and in some cases after few minutes]
ERROR #wl_cfg80211_scan: WLC_SCAN error (-22)
Get an IP using dhclient using dhclient wlp2s0
But nohing happens
Ping command : Name or sarvice not known
If I run wpa_supplicant without -B I get some repeating errors:
Device or resource busy
wlp2s0: Failed to initiate AP scan
wlp2s0: Trying to associate with [MAC] (SSID='MyNetName' freq=2462 MHz)
Operation not supported
wlp2s0: Association request to the driver failed
....
if I add -D nl80211 to wpa_supplicant call I get same errors without "Device or resource busy"
What I am doing wrong?

KGDB remote debugging error

I am trying to debug the Linux kernel using kgdb. I am using qemu as target machine. Ubuntu 12.04 is my host OS. I tried this command
cyborg#skynet:~$ qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/bin/sh kgdboc=ttyAMA0,115200 kgdbwait"
It will boot and wait displaying
kgdb: Waiting for connection from remote gdb
And when I try to debug using gdb on linux host using the commands
cyborg#skynet: arm-none-linux-gnueabi-gdb vmlinux
(gdb): set remotebaud 115200
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Malformed response to offset query, timeout
I am not really getting what I am missing !
P.S. I compiled the linux kernel 2.6.39.4 with KGDB options enabled. And I followed these instructions to run kernel on qemu.
If you reference /dev/ttyS0 on the host gdb will try to use the physical serial port present. You have to connect qemu's emulated serial port to gdb instead.
Reading the qemu manual, apparently you can redirect the emulated port to tcp networking, by adding something like: -serial tcp::1234,server to the qemu command line. In gdb you can then connect using target remote :1234.
There is no real reason to use kgdb when your running within Qemu. You can simply specify something like "-gdb tcp::8888" on the Qemu command line and activate the GDB stub. You can then connect to the stub with an ARM aware GDB:
target remote:8888
And debug away. You may find the following gdb helper scripts useful

Resources