Enabling GDB Port on VMs

106 views
Skip to first unread message

Alexander Hussey

unread,
May 31, 2022, 10:00:21 PM5/31/22
to kubevi...@googlegroups.com
Hi everyone,
TL;DR - I am looking to have a feature implemented which enables exposing the GDB port on a VM.

Please find my GitHub issue for reference: https://github.com/kubevirt/kubevirt/issues/7714

I plan to join in on the next KubeVirt/Community meeting and would be happy to discuss it there also.

I understand there will need to be some modifications to my issue and I welcome all critique. I am also happy to try and help dev a solution, but please note writing in Go is not one of my strengths.

Please also find a GDB hook sidecar that I have developed for testing purposes. It is based heavily on the example hook sidecar.
https://github.com/ahussey-redhat/kubevirt/tree/gdb/cmd/gdb-hook-sidecar


Kind regards,
Alex

--

Alexander Hussey, RHCSA, RHCE

He/Him/His

Consultant

Red Hat

40 Marcus Clarke Street, Canberra, ACT,2601

ahu...@redhat.com   
M: 0409-516-967    

Alexander Hussey

unread,
Jun 1, 2022, 8:42:19 PM6/1/22
to kubevirt-dev
Hi everyone,
As a result of the meeting we are going to test enabling qemu gdb by exec-ing into the virt-launcher and using the qemu monitor command.

I just wanted to get an understanding/appreciation for how I might execute this command. It seems like it is a function in [libvirt-go](https://pkg.go.dev/github.com/libvirt/libvirt-go#Domain.QemuMonitorCommand) and [libvirt-qemu](https://libvirt.org/html/libvirt-libvirt-qemu.html#virDomainQemuMonitorCommand). So in order to execute that function in the virt-launcher container, would I need to compile a Go script which imports the appropriate libraries (libvirt-go ?) and then calls `<domain>.QemuMonitorCommand('-gdb tcp::1234')`.

Please excuse if wrong syntax, I'm not fluent in Go.

Kind regards,
Alex

Miguel Duarte de Mora Barroso

unread,
Jun 2, 2022, 4:14:17 AM6/2/22
to Alexander Hussey, kubevirt-dev
On Thu, Jun 2, 2022 at 2:42 AM Alexander Hussey <ahu...@redhat.com> wrote:
Hi everyone,
As a result of the meeting we are going to test enabling qemu gdb by exec-ing into the virt-launcher and using the qemu monitor command.

I just wanted to get an understanding/appreciation for how I might execute this command. It seems like it is a function in [libvirt-go](https://pkg.go.dev/github.com/libvirt/libvirt-go#Domain.QemuMonitorCommand) and [libvirt-qemu](https://libvirt.org/html/libvirt-libvirt-qemu.html#virDomainQemuMonitorCommand). So in order to execute that function in the virt-launcher container, would I need to compile a Go script which imports the appropriate libraries (libvirt-go ?) and then calls `<domain>.QemuMonitorCommand('-gdb tcp::1234')`.

I think you should add another command to [0], which would wrap over the functions you have listed above,
then ensure the virt-launcher container features this binary. 

IIUC, for that, you'll need to adapt the launcher pod bazel file, in [1], adding your new command to the srcs list.


Please excuse if wrong syntax, I'm not fluent in Go.

Kind regards,
Alex

On Wednesday, June 1, 2022 at 12:00:21 PM UTC+10 Alexander Hussey wrote:
Hi everyone,
TL;DR - I am looking to have a feature implemented which enables exposing the GDB port on a VM.

Please find my GitHub issue for reference: https://github.com/kubevirt/kubevirt/issues/7714

I plan to join in on the next KubeVirt/Community meeting and would be happy to discuss it there also.

I understand there will need to be some modifications to my issue and I welcome all critique. I am also happy to try and help dev a solution, but please note writing in Go is not one of my strengths.

Please also find a GDB hook sidecar that I have developed for testing purposes. It is based heavily on the example hook sidecar.
https://github.com/ahussey-redhat/kubevirt/tree/gdb/cmd/gdb-hook-sidecar



Kind regards,
Alex

--

Alexander Hussey, RHCSA, RHCE

He/Him/His

Consultant

Red Hat

40 Marcus Clarke Street, Canberra, ACT,2601

ahu...@redhat.com   
M: 0409-516-967    

--
You received this message because you are subscribed to the Google Groups "kubevirt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubevirt-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubevirt-dev/c1c4217f-ec0d-432c-810e-b8409b59c498n%40googlegroups.com.

dvo...@redhat.com

unread,
Jun 3, 2022, 8:51:39 AM6/3/22
to kubevirt-dev
On Wednesday, June 1, 2022 at 8:42:19 PM UTC-4 Alexander Hussey wrote:
Hi everyone,

As a result of the meeting we are going to test enabling qemu gdb by exec-ing into the virt-launcher and using the qemu monitor command.

I just wanted to get an understanding/appreciation for how I might execute this command. It seems like it is a function in [libvirt-go](https://pkg.go.dev/github.com/libvirt/libvirt-go#Domain.QemuMonitorCommand) and [libvirt-qemu](https://libvirt.org/html/libvirt-libvirt-qemu.html#virDomainQemuMonitorCommand). So in order to execute that function in the virt-launcher container, would I need to compile a Go script which imports the appropriate libraries (libvirt-go ?) and then calls `<domain>.QemuMonitorCommand('-gdb tcp::1234')`.


If you need some custom go login in the VMI pod, the easiest way to prototype the behavior you're wanting is to add it to virt-launcher itself [0].  This binary is already a part of the build system, already has libvirt-go, and is already present within the VMI pod. All you'd need to do is add your logic to the binary and you'll have it available when you pod exec into the VMI pod.

For example, you could had a new cli option to virt-launcher to do whatever it is you're needing and exit. Then in the VMI pod you'd just execute another virt-launcher process with your special arg to exercise the behavior.

Without completely understanding the behavior you're wanting, I can't say with certainty that we'd actually want to permanently place this logic in virt-launcher (it is possible though), but it's a clear entry point if you're wanting to simply have some custom logic available to experiment with in the VMI pod.

- David

Alexander Hussey

unread,
Jun 28, 2022, 9:54:12 PM6/28/22
to kubevirt-dev
Hi David,

Do you think I could make use of `QemuAgentCommand`, which is already defined in the virt-launcher CLI?
```
QemuAgentCommand(command string, domainName string)
```
Or this to interact with the guest agent?

- Alex

Luboslav Pivarc

unread,
Jun 29, 2022, 5:23:35 AM6/29/22
to Alexander Hussey, kubevirt-dev
Hi Alexander,

You are right, this is only for a guest agent. You can find out more here https://libvirt.org/html/libvirt-libvirt-qemu.html#virDomainQemuAgentCommand

Lubo

--
You received this message because you are subscribed to the Google Groups "kubevirt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubevirt-dev...@googlegroups.com.

Alexander Hussey

unread,
Jun 29, 2022, 8:08:06 PM6/29/22
to kubevirt-dev
Thanks for confirming that Lubo.

I will look to write a separate function to create the functionality I'm looking for.

Kind regards,
Alex

Reply all
Reply to author
Forward
0 new messages