changeset 42:09fe50fc0629

try to fix debug mode
author innparusu
date Mon, 21 Dec 2015 20:37:49 +0900
parents 517f130f301a
children 3eb0b5edad30
files ie-virsh.c newvm.py
diffstat 2 files changed, 27 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ie-virsh.c	Sun Nov 15 12:27:56 2015 +0900
+++ b/ie-virsh.c	Mon Dec 21 20:37:49 2015 +0900
@@ -138,7 +138,7 @@
 void
 usage()
 {
-    printf("Usage: COMMAND [define|list|start|destroy|dumpxml|undefine|console] [vm-name]\n");
+    printf("Usage: COMMAND [define|define-gdb|list|start|destroy|dumpxml|undefine|console] [vm-name]\n");
     printf("   vm-name should be 01 - 04\n");
 }
 
@@ -230,7 +230,7 @@
 }
 
 void
-create_new_vm(const char const *name, const char const *vm_name, char* xml_name){
+create_new_vm(const char const *name, const char const *vm_name, char* xml_name, int debug, char* debug_port){
     if (check_name(name)) {
         fprintf(stderr, bad_name);
         exit(0);
@@ -239,10 +239,12 @@
     strncpy(vm_path, vm_name, VM_NAME_LENGTH);
     change_delimiter_to_slash(vm_path);
     char exec[1024];
-    strncpy(exec, newvm_command ,900);
-    strncat(exec, vm_path,1000);
+    if (debug) {
+    	snprintf(exec, 1024, "%s %s -d %s", newvm_command, vm_path, debug_port);
+    } else {
+    	snprintf(exec, 1024, "%s %s", newvm_command, vm_path);
+    }
     fprintf(stdout, "excuting %s\n",exec );
-    printf("%s\n", vm_path);
     system(exec);
     strncpy(xml_name, vm_path,900);
     strncat(xml_name,".xml",1000);
@@ -331,7 +333,17 @@
         if (argc<3) {usage(); exit(1);}
         char xml_name[1024];
         xml_name[0] = 0;
-        create_new_vm(argv[2], vm_name, xml_name);
+        create_new_vm(argv[2], vm_name, xml_name, 0);
+        /* 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 ) {
+        if (argc<3) {usage(); exit(1);}
+        char xml_name[1024];
+        xml_name[0] = 0;
+        create_new_vm(argv[2], vm_name, xml_name, 1);
         /* chdir("/usr/local/etc/libvirt/qemu"); */
         chdir("/etc/libvirt/qemu");
         if (execl(command, command, define_command, xml_name, NULL) < 0) {
@@ -343,24 +355,6 @@
         if (execl(command, command, undefine_command, vm_name, NULL) < 0) {
             perror("Execl:");
         }
-    } else if (strncmp(argv[1], debug_command, 5) == 0) {
-        char *user_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH);
-        strncpy(user_name,  "\0", 1);
-        make_vm_name(user_name, account_type, name, debug_command);
-
-        char str_uid[1024];
-        sprintf(str_uid, "%d", uid);
-
-        char debug_exec[1026];
-        sprintf(debug_exec, "/usr/local/bin/debugvm.py --name %s --uid %s --config %s", user_name, str_uid, "/etc/libvirt/qemu/debugvm.xml");
-        free(user_name);
-
-        printf("debug_exec::%s \n", debug_exec);
-
-        char gdb_exec[1024];
-        strncpy(gdb_exec, "/usr/bin/gdb",900);
-//      strncat(gdb_exec, " /usr/lib/debug/lib/modules/3.17.4-200.fc20.x86_64/vmlinux", 900);
-//      system(gdb_exec);
     } else {
         printf("%s is invalid command.\n", argv[1]);
         usage();
--- a/newvm.py	Sun Nov 15 12:27:56 2015 +0900
+++ b/newvm.py	Mon Dec 21 20:37:49 2015 +0900
@@ -83,11 +83,13 @@
         help="Template VM XML config file");
 parser.add_option("-i", "--iso", dest="iso",
         help="When boot VM from ISO");
+parser.add_option("-d", "--debug", dest="debug",
+        help="Kernel debug mode");
 
 (options, args) = parser.parse_args();
 
 if not options.name or not options.config:
-    print "Usage %s -n name -c template_xml" % sys.argv[0]
+    print "Usage %s -n name -c template_xml [-d debug_port]" % sys.argv[0]
     sys.exit(1)
 
 config = ET.parse(options.config)
@@ -113,6 +115,12 @@
 disk_ext = os.path.splitext(disk_old)[1]
 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>"
 
 if os.path.exists(vm_name + '.xml'):
     print "File %s.xml exists, abort" % vm_name