changeset 43:3eb0b5edad30

Support kernel debug without random port
author atton
date Wed, 13 Jan 2016 20:33:55 +0900
parents 09fe50fc0629
children 546504699402
files ie-virsh.c newvm.py
diffstat 2 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ie-virsh.c	Mon Dec 21 20:37:49 2015 +0900
+++ b/ie-virsh.c	Wed Jan 13 20:33:55 2016 +0900
@@ -1,6 +1,7 @@
 
 #include <stdlib.h>
 #include <unistd.h>
+#include <stdbool.h>
 
 #include <stdio.h>
 #include <sys/types.h>
@@ -23,6 +24,7 @@
 #define dumpxml_command "dumpxml"
 #define console_command "console"
 #define debug_command "debug"
+#define define_gdb_command "define-gdb"
 
 
 const char *guests[] = {};
@@ -230,7 +232,7 @@
 }
 
 void
-create_new_vm(const char const *name, const char const *vm_name, char* xml_name, int debug, char* debug_port){
+create_new_vm(const char const *name, const char const *vm_name, char* xml_name, int debug_kernel){
     if (check_name(name)) {
         fprintf(stderr, bad_name);
         exit(0);
@@ -239,10 +241,10 @@
     strncpy(vm_path, vm_name, VM_NAME_LENGTH);
     change_delimiter_to_slash(vm_path);
     char exec[1024];
-    if (debug) {
-    	snprintf(exec, 1024, "%s %s -d %s", newvm_command, vm_path, debug_port);
+    if (debug_kernel) {
+        snprintf(exec, 1024, "%s %s -d", newvm_command, vm_path);
     } else {
-    	snprintf(exec, 1024, "%s %s", newvm_command, vm_path);
+        snprintf(exec, 1024, "%s %s", newvm_command, vm_path);
     }
     fprintf(stdout, "excuting %s\n",exec );
     system(exec);
@@ -333,17 +335,17 @@
         if (argc<3) {usage(); exit(1);}
         char xml_name[1024];
         xml_name[0] = 0;
-        create_new_vm(argv[2], vm_name, xml_name, 0);
+        create_new_vm(argv[2], vm_name, xml_name, false);
         /* chdir("/usr/local/etc/libvirt/qemu"); */
         chdir("/etc/libvirt/qemu");
         if (execl(command, command, define_command, xml_name, NULL) < 0) {
             perror("Execl:");
         }
-    } else if (strncmp(argv[1], define_gdb_command, 10) == 0 ) {
+    } else if (strcmp(argv[1], define_gdb_command) == 0 ) {
         if (argc<3) {usage(); exit(1);}
         char xml_name[1024];
         xml_name[0] = 0;
-        create_new_vm(argv[2], vm_name, xml_name, 1);
+        create_new_vm(argv[2], vm_name, xml_name, true);
         /* chdir("/usr/local/etc/libvirt/qemu"); */
         chdir("/etc/libvirt/qemu");
         if (execl(command, command, define_command, xml_name, NULL) < 0) {
--- a/newvm.py	Mon Dec 21 20:37:49 2015 +0900
+++ b/newvm.py	Wed Jan 13 20:33:55 2016 +0900
@@ -76,6 +76,9 @@
             random.randint(0x00, 0xff) ]
     return ':'.join(map(lambda x: "%02x" % x, mac))
 
+def gen_debug_port():
+    return 10000
+
 parser = OptionParser();
 parser.add_option("-n", "--name", dest="name",
         help="VM name");
@@ -116,11 +119,12 @@
 disk_image = disk_path + '/' + vm_name + disk_ext
 disk.attrib['file'] = disk_image
 if (options.debug):
- "<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
-  <qemu:commandline>
-    <qemu:arg value='-s'/>
-    <qemu:arg value='-S'/>
-  </qemu:commandline>"
+    # http://wiki.libvirt.org/page/QEMUSwitchToLibvirt
+    domain_attr               = config.getroot().attrib
+    domain_attr['xmlns:qemu'] = "'http://libvirt.org/schemas/domain/qemu/1.0'"
+    qemu_elem                 = ET.Element('qemu:commandline')
+    ET.SubElement(qemu_elem, 'qemu', {'value' => '-S'})
+    ET.SubElement(qemu_elem, 'qemu', {'value' => ('-s %d' % gen_debug_port())})
 
 if os.path.exists(vm_name + '.xml'):
     print "File %s.xml exists, abort" % vm_name