I am having issues with serial and usb connection between host and target. Below is my setup. Both host and target do NOT have any serial (DB9) ports.
Host : Running windows + VMshare + Ubuntu
Target: Running linux kernel 3.19 . Has a MINI usb port which acts as a serial port, i think its ( CP210x uart to usb )
Connection 1 : Host ( USB to DB9 male-PL2303) + DB9 female to female + (DB9 male to USB) target.
Connection 2 : Host ( USB ) --cable-- (USB mini) Target
Host ( ubuntu VM ), can recognize the USB device (both connections types ) as /dev/ttyUSB0. The device does not show up on the windows device manager since VM takes over the device control.
Target boots into UEFI shell. I modify the syslinux.cfg file to append "kgdbwait kgdboc =ttyS0, 115200" to APPEND flag. Save the change ( press F2) then exit ( press F3 ). Boot into the image. Target now enters the kdb prompt with the following message
kgdb: Waiting for connection from remote gdb...
Entering kdb ( current= <64bit address>, pid 1) on processor 0 due to Keyboard Entry
Kgdb > _
on the host side, i do the following commands and below is error
root#ubuntu: cd /images
root#ubuntu: sudo gdb ./vmlinux
Reading symbols from ./vmlinux done.
(gdb)
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Bogus trace status reply from target: timeout
Experiments i tried
on Host i used " target remote /dev/ttyS0 " , still same issue
Tried different cables in each connection ( 1 and 2 ) mentioned above
on Target removed the edit in the syslinux.cfg file in UEFI shell, booted the image and entered kgdb using "echo g > /proc/sysrq-trigger"
All kernel configuration related to KGDB* , KGDB_SERIAL*, KGDB_USB* are enabled
all available baud rates
Questions
If i use "kgdbwait kgdboc=ttyUSB0, 115200" instead of " kgdbwait kgdboc=ttyS0, 115200" the target does NOT halt. When the target boots up fully to login prompt, i can see the device is recognized as ttyUSB0 when using connection 1. However as it does not stop does that mean, KGDB using USB does not work ? or for USB debug , i need to use direct USB--USB wire ( connection 3 ) ?
does syslinux.cfg support USB debug? becuase there is a SERIAL flag which has value" 0, 115200 " where 0 refers to ttyS0. syslinux documentation does not have any values for USB type device.
using connection 2, why am i seeing the timeout and packet error issues
occasionally with connection 2, when i execute " target remote /dev/ttyUSB0 " on the host, i notice junk characters on the target. So there is some communication happening, so tried different baud rates still same issue. Does this indicate anything inherently wrong with my setup?
In many online forums/ documents i do not see the "entering kdb due to keyboard entry" when the kernel enters kdb prompt. is this unusual?
The setup of remote kgdb debug is a bit tedious. There are several prerequisites/limitations for the kgdb to work. I will try to break it down.
You have to prepare two machines in this setup.
HOST: Where the agent-proxy & GDB installed.
TARGET: The Linux system being debugged.
Connection Setup
[Host /dev/ttyUSB0] USB to Serial --------- COM port [Target /dev/ttyS0]
On the TARGET side, it's not possible to use the USB interface with kgdb. This is because all the USB-Serial driver (CP210x, PL2303, ...etc) did not implement the polling hook. You have to connect the COM port with a serial cable directly. It is ok to use the USB interface on the HOST side. Since it is a serial connection, you have to use a USB-to-Serial converter and install the proper driver on HOST.
Set the proper baud rate on both sides:
[Target] stty -F /dev/ttyS0 115200
[Host] stty -F /dev/ttyUSB0 115200
Make sure the serial connection works on both direction. You can use:
[Host] cat /dev/ttyUSB0
[Target] echo 'from TARGET to HOST' > /dev/ttyS0
[Target] cat /dev/ttyS0
[Host] echo 'from HOST to TARGET' > /dev/ttyUSB0
You should see the messages on both side of machine. If not, there might be some problems on the cable or driver.
Compile Kernel
Enable KGDB* , KGDB_SERIAL*, KGDB_USB*, DEBUG_INFO, DEBUG_INFO_DWARF4, MAGIC_SYSRQ in the kernel config. Compile and install on the TARGET.
The main purpose here is to enable KGDB feature & preserve debug information in vmlinux.
agent-proxy Setup
agent-proxy acts as a proxy for the TARGET's serial port. It splits up the serial port for multiplexing. One for primary console I/O, the other for GDB session. Thus, we can work on both simultaneously. You should run the agent-proxy on HOST machine.
git clone http://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
cd agent-proxy ; make
./agent-proxy 5550^5551 0 /dev/ttyUSB0,115200
This will redirect:
TARGET's console to HOST:5550
TARGET's kgdb listening port to HOST:5551
Start To Debug
First, open the primary console:
[Host] telnet localhost 5550
Entering the kdb mode, either by:
[Target] echo ttyS0,115200 > /sys/module/kgdboc/parameters/kgdboc
[Target] dmesg | tail
(you should see KGDB: Registered I/O driver kgdboc, otherwise it failed)
[Target] echo g >/proc/sysrq-trigger
Or, by adding the following kernel parameters in TARGET's bootloader (for early kernel debug):
console=tty0 console=ttyS0,115200 kgdbwait kgdboc=ttyS0,115200
The TARGET machine will halt immediately once it breaks into the kdb.
At the same time, you will see a kdb prompt on the primary console:
....
Entering kdb (current=0xcb846c80, pid 2301) on processor 3 due to Keyboard Entry
[3]kdb>
Type kgdb then enter. The TARGET is now pending for remote GDB's connection. We will connect it from the HOST.
Host> gdb vmlinux
(gdb) target remote localhost:5551
Remote debugging using localhost:5551
kgdb_breakpoint () at kernel/debug/debug_core.c:1072
1072 wmb(); /* Sync point after breakpoint */
(gdb)
Enjoy your kernel debugging!
Related
Im very New to KGDB, Im getting problem when im connecting the target from Host, Getting The following Error.
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
Ignoring packet error, continuing...
warning: unrecognized item "swreak" in "qSupported" response
warning: unrecognized item "ReloInsn" in "qSupported" response
warning: unrecognized item "QTread'
[3]kdb> " in "qSupported" response
Bogus trace status reply from target: qTStatus
...
#
The Procedure Im following is :
[Target] stty -F /dev/ttyS0 115200
[Host] stty -F /dev/ttyUSB0 115200
Make sure the serial connection works on both direction. You can use:
[Host] cat /dev/ttyUSB0
[Target] echo 'from TARGET to HOST' > /dev/ttyS0
[Target] cat /dev/ttyS0
[Host] echo 'from HOST to TARGET' > /dev/ttyUSB0
You should see the messages on both side of machine. If not, there
might be some problems on the cable or driver.
Compile Kernel
Enable KGDB* , KGDB_SERIAL*, KGDB_USB*, DEBUG_INFO, DEBUG_INFO_DWARF4,
MAGIC_SYSRQ in the kernel config. Compile and install on the TARGET.
The main purpose here is to enable KGDB feature & preserve debug
information in vmlinux.
agent-proxy Setup
agent-proxy acts as a proxy for the TARGET's serial port. It splits up
the serial port for multiplexing. One for primary console I/O, the
other for GDB session. Thus, we can work on both simultaneously. You
should run the agent-proxy on HOST machine.
git clone http://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
cd agent-proxy ; make
./agent-proxy 5550^5551 0 /dev/ttyUSB0,115200
This will redirect:
TARGET's console to HOST:5550
TARGET's kgdb listening port to HOST:5551
Start To Debug
First, open the primary console:
[Host] telnet localhost 5550
Entering the kdb mode, either by:
[Target] echo ttyS0,115200 > /sys/module/kgdboc/parameters/kgdboc
[Target] dmesg | tail
(you should see KGDB: Registered I/O driver kgdboc, otherwise it
failed)
[Target] echo g >/proc/sysrq-trigger
Host> gdb vmlinux
(gdb) target remote localhost:5551
Remote debugging using localhost:5551
kgdb_breakpoint () at kernel/debug/debug_core.c:1072
1072 wmb(); /* Sync point after breakpoint */
(gdb)
#
when i type kgdb in target mission it is getting error as Permission denied as shown below
[3]kdb> kgdb
diag: -22: Permission denied
..., I would appreciate the clear answer in steps..., Thanks in advance
diag: -22: Permission denied
That error means that access to debugger functions is prohibited by default in you kernel. In order to unlock debugger you need exec this command:
echo 1 > /sys/module/kdb/parameters/cmd_enable
or add a Kernel Boot Parameter:
kdb.cmd_enable=1
More info here
I am a total newbie and trying to debug an application which should receive a binary via TCP. When I launch it, it begins to listen several ports, I execute cat myfile | nc port_number in another terminal (apps terminal is busy) and the app runs. But I have no idea how to debug it in Qt creator. Everything I found on the Internet seems irrelevant to my problem.
[Apologies for posting a non-programming topic, but I thought this post would help others in need.]
I'm trying to get synergy working between a PC and a Mac.
I'm using auto-config, and all the default settings. It works perfectly with the mac as the server.
However, when the PC is the server and the mac as client, the PC first detects a zeroconf client, but then just sits there with no more log messages. Meanwhile, the mac client keeps "timing out" and never connects.
Things I've checked:
Windows Firewall is correctly configured to let synergy run - there
are rules allowing TCP and UDP connections for the synergy
executables
I've tried both 32 bit and 64 bit synergy versions
I've tried auto-config client, and also tried using the screen name and
the IP address.
I've tried running with elevated permissions
I can PING each machine from the other using the terminal - we are
connected to the same Wi-Fi network!
I have a Macbook (10.11) called Ian-Mac.local, with IP address 192.168.0.6.
I have a Windows 10 Laptop called Ian-PC with 5 different IP addresses listed. The default one is 192.168.56.1
Here's the debug-level log from the PC:
[2016-12-06T12:04:49] NOTE: started server, waiting for clients
[2016-12-06T12:04:49] DEBUG: event queue is ready
[2016-12-06T12:04:49] DEBUG: add pending events to buffer
[2016-12-06T12:04:49] DEBUG: screen "Ian-PC" shape changed
[2016-12-06T12:04:49] DEBUG: accepted ipc client connection
[2016-12-06T12:04:49] DEBUG: start ipc handle data
[2016-12-06T12:04:49] DEBUG: ipc read: IHEL
[2016-12-06T12:04:49] DEBUG: finished ipc handle data
[2016-12-06T12:04:49] DEBUG: ipc hello, type=node
[2016-12-06T12:04:49] INFO: watchdog status: ok
[2016-12-06T12:04:50] DEBUG: started process, session=1, elevated: yes, command="C:/Program Files (x86)/Synergy/synergys.exe" -f --no-tray --debug DEBUG --name Ian-PC --ipc --enable-drag-drop --profile-dir "C:\Users\Ian\AppData\Local" -c "C:/Users/Ian/AppData/Local/Temp/qt_temp.ZU7304" --address :24800 --serial-key MY_LICENCE_KEY --res-w 1920 --res-h 1080 --prm-wc 960 --prm-hc 540
[2016-12-06T12:04:55] INFO: zeroconf client detected: Ian-Mac.local
Here's the debug-level log from the mac:
2016-12-06T12:12:02] INFO: starting client
[2016-12-06T12:12:02] INFO: command: /Applications/Synergy.app/Contents/MacOS/synergyc -f --no-tray --debug DEBUG --name Ian-Mac.local --enable-drag-drop 192.168.56.1:24800
[2016-12-06T12:12:02] INFO: config file: /var/folders/k3/rzjn4xxj5tz3j1ygq72cwyj00000gp/T/Synergy.txK899
[2016-12-06T12:12:02] INFO: log level: DEBUG
[2016-12-06T12:12:03] INFO: drag and drop enabled
[2016-12-06T12:12:03] DEBUG: screen shape: center=0,0 size=1920x1080 on 1 display
[2016-12-06T12:12:03] DEBUG: starting watchSystemPowerThread
[2016-12-06T12:12:03] DEBUG: adopting new buffer
[2016-12-06T12:12:03] DEBUG: opened display
[2016-12-06T12:12:03] NOTE: started client
[2016-12-06T12:12:03] NOTE: connecting to '192.168.56.1': 192.168.56.1:24800
[2016-12-06T12:12:03] DEBUG: waiting for carbon loop
[2016-12-06T12:12:03] DEBUG: started watchSystemPowerThread
[2016-12-06T12:12:03] DEBUG: waiting for event loop
[2016-12-06T12:12:03] DEBUG: event queue is ready
[2016-12-06T12:12:03] DEBUG: signalling carbon loop ready
[2016-12-06T12:12:03] DEBUG: add pending events to buffer
[2016-12-06T12:12:03] DEBUG: starting carbon loop
[2016-12-06T12:12:03] DEBUG: carbon loop ready
2016-12-06 12:12:03.091 synergyc[1059:39119] starting cocoa loop
[2016-12-06T12:12:18] WARNING: failed to connect to server: Timed out
[2016-12-06T12:12:18] DEBUG: retry in 1 seconds
[2016-12-06T12:12:19] NOTE: connecting to '192.168.56.1': 192.168.56.1:24800
[2016-12-06T12:12:34] WARNING: failed to connect to server: Timed out
[2016-12-06T12:12:34] DEBUG: retry in 1 seconds
Synergy picked up the wrong IP address!
I have a Windows 10 Laptop called Ian-PC with 5 different IP addresses
listed. The default one is 192.168.56.1
Running IPCONFIG on the windows machine showed that the IP address picked up by synergy was for my "Ethernet adapter VirtualBox Host-Only Network". The issue was due to my installation of "Virtual Box".
Instead of using the default IP, I entered the one listed by IPCONFIG as "Wireless LAN adapter Wi-Fi", which was 192.168.0.4
I had this problem as well - but actually I was attempting to connect an iMac to a MacBook Pro running Win10 via Bootcamp (so basically the same problem). When I ran ipconfig and obtained the IP address for my wifi adapter, everything connected perfectly.
Thanks for giving me back the rest of my evening.
I was having the same issues with Barrier. Which is a fork of Synergy Core and Open Sourced.
So I'm posting how I resolved it. It might help somebody.
I had the same issues. After an hour of searching Internet, I got it working.
Barrier was picking up the wrong IP Address which was my Ethernet IP Address. Thanks to Ians Answer
So make sure you run ipconfig on the server, in my case, it's Windows 10
and see the correct IP Address Under Wireless LAN adapter Wi-Fi IPV4 address.
Make sure you give the same Screen Name
In my case, the name is mac (Windows 10 Screenshot)
Mac OS Screenshot
I had problems if my Wifi is set to password-protected (which is just my mobile hotspot). So to get around that I made it public and limited the connections to it.
That's it. I hope it helps somebody :)
I used to the St-write to burn .bin to the STM32F4 and saw the message which I expected. Now, I hope to understand how GPIO init. Hence, I use OpenOCD and arm-none-eabi-gdb to do that. Here, it is my process.
$ minicom
$ openocd -f /opt/openocd/share/openocd/scripts/board/stm32f4discovery.cfg
$ arm-none-eabi-gdb main.elf
(gdb) target remote localhost:3333
(gdb) localhost:3333: Connection timed out.
How do I check the port of OpenOCD? Why does it occur timeout?
That certainly means that openocd did not start or that the port is busy.
Usually, you use :
openocd -f board/stm32f4discovery.cfg
You should check that your session is running.
Are you running a virtual linux machine on a windows host?
If so, you probably need to replace localhost with 10.0.0.2 (or whatever your windows IP is).
A good way to know, is to telnet to the openOCD address and port 4444 and see if you get the openOCD prompt, and can type a few commands.
I am trying to debug a device driver which is crashing the kernel on a Mac using a remote machine running gdb (trying to follow the instructions here). Both machines are connected to the same network by Ethernet (same router even, and both can access the network). I have also set nvram boot-args="debug=0x144" on the target and restarted.
I then load the kernel extension on the target as usual. On the host machine I start gdb like this:
$ gdb -arch i386 /Volumes/KernelDebugKit/mach_kernel
Once in gdb, I load the kernel macros and set up for remote attachment
(gdb) source /Volumes/KernelDebugKit/kgmacros
(gdb) target remote-kdp
(gdb) kdp-reattach 11.22.33.44
However, the last command then does not make a connection and I get an endless spool of
kdp_reply_wait: error from kdp_receive: receive timeout exceeded
kdp_transaction (remote_connect): transaction timed out
kdp_transaction (remote_connect): re-sending transaction
What is the correct way to get gdb connected to the target machine?
There are a number of ways to break into the target, including:
Kernel panic, as stated in your answer above.
Non-maskable interrupt, which is triggered by the cmd-option-ctrl-shift-esc key combination.
Code a break in your kernel extension using PE_enter_debugger(), which is declared in pexpert/pexpert.h
Halt at boot by setting DB_HALT (0x01) in the NVRAM boot-args value.
Additionally, you may need to set a persistent ARP table entry, as the target is unable to respond to ARP requests while stopped in the debugger. I use the following in my debugger-launch shell script to set the ARP entry if it doesn't already exist:
if !(arp -a -n -i en0 | grep '10\.211\.55\.10[)] at 0:1c:42:d7:29:47 on en0 permanent' > /dev/null) ; then
echo "Adding arp entry"
sudo arp -s 10.211.55.10 00:1c:42:d7:29:47
fi
Someone more expert could probably improve on my bit of shell script.
All of the above is documented in http://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KernelProgramming/KernelProgramming.pdf.
The answer is simply to make sure the target has a kernel panic before you try to attach gdb from the host.