GNS3 / dynamips

Dynamips development
GNU General Public License v2.0
353 stars 95 forks source link

Dynamips on Mac OS X crashes #60

Closed grossmj closed 9 years ago

grossmj commented 9 years ago

Any Dynamips version compiled on Mac OS X crashes since the introduction of the cmake compilation system.

The compilation itself goes well but Dynamips crashes as soon as you try to start an IOS image.

./dynamips -P 3725 ~/GNS3/images/IOS/c3725-adventerprisek9-mz.124-15.T14.image

First time it boots I get ??? all over the terminal. I am forced to kill the dymamips process.

Second time, I get a segmentation fault.

Cisco Router Simulation Platform (version 0.2.15-dev-amd64/Darwin unstable)
Copyright (c) 2005-2011 Christophe Fillot.
Build date: Nov 29 2014 17:59:01

Local UUID: AFB87940-743D-4B1A-9D50-67E3A6EACBCF

IOS image file: /Users/grossmj/GNS3/images/IOS/c3725-adventerprisek9-mz.124-15.T14.image

ILT: loaded table "mips64j" from cache.
ILT: loaded table "mips64e" from cache.
ILT: loaded table "ppc32j" from cache.
ILT: loaded table "ppc32e" from cache.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'default' (id 0):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 112 Kb
  IOS image  : /Users/grossmj/GNS3/images/IOS/c3745-adventerprisek9-mz.124-15.T14.image

Loading ELF file '/Users/grossmj/GNS3/images/IOS/c3745-adventerprisek9-mz.124-15.T14.image'...
ELF entry point: 0x80008000

C3725 'default': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
VM default: starting CPU!
Segmentation fault: 11

This may have something to do with the microcode because this is at this point that it is supposed to be loaded.

julien-duponchelle commented 9 years ago

I confirm the issue with Mac OS X Yosemite:

Cisco Router Simulation Platform (version 0.2.15-dev-amd64/Darwin unstable)
Copyright (c) 2005-2011 Christophe Fillot.
Build date: Dec 28 2014 17:10:24

Local UUID: E430CF2F-35B0-4876-AD1E-8C585D8AD61B

IOS image file: /Users/noplay/GNS3/images/IOS/c1700-adventerprisek9-mz.124-15.T14.image

ILT: loaded table "mips64j" from cache.
ILT: loaded table "mips64e" from cache.
ILT: loaded table "ppc32j" from cache.
ILT: loaded table "ppc32e" from cache.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'default' (id 0):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 112 Kb
  IOS image  : /Users/noplay/GNS3/images/IOS/c1700-adventerprisek9-mz.124-15.T14.image

Loading ELF file '/Users/noplay/GNS3/images/IOS/c1700-adventerprisek9-mz.124-15.T14.image'...
ELF entry point: 0x80008000

C3725 'default': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
VM default: starting CPU!

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
[Switching to process 16256 thread 0x1703]
0x00007fff99e6e432 in stack_not_16_byte_aligned_error ()

How can i enable symbol debugging for gdb with cmake?

grossmj commented 9 years ago

Hi don't really know cmake. You can still try to find the problem but if you can't then just use a compiled version of Dynamips: https://community.gns3.com/community/software/download/appliances/blog/2014/10/03/dynamips/

LocutusOfBorg commented 9 years ago

what about use cmake with -DCMAKE_BUILD_TYPE=DEBUG or export CFLAGS+=-g and export CXXFLAGS+=-g (or whatever it is needed)

let me know if this doesn't help (i'm not sure if -g is the correct flag)

ghost commented 9 years ago

I compared the compile definitions from v0.2.12 (old Makefile system) with those created by cmake.

cmake always adds -DMAC64HACK on OSX 64 builds while the old Makefile adds this definition only on stable builds.

I changed the cmake configuration to behave like the old Makefile:

diff --git a/cmake/configure.cmake b/cmake/configure.cmake
index de7ffdc..b290393 100644
--- a/cmake/configure.cmake
+++ b/cmake/configure.cmake
@@ -33,9 +33,6 @@ set ( PPC32_ARCH_INC_FILE "\"ppc32_${DYNAMIPS_ARCH}_trans.h\"" )
 list ( APPEND DYNAMIPS_DEFINITIONS "-DJIT_ARCH=${JIT_ARCH}" "-DJIT_CPU=${JIT_CPU}"
    "-DMIPS64_ARCH_INC_FILE=${MIPS64_ARCH_INC_FILE}"
    "-DPPC32_ARCH_INC_FILE=${PPC32_ARCH_INC_FILE}" )
-if ( APPLE AND "amd64" STREQUAL "${DYNAMIPS_ARCH}" )
-   list ( APPEND DYNAMIPS_DEFINITIONS "-DMAC64HACK" )
-endif()
 print_variables ( DYNAMIPS_ARCH )

 # Target code:
diff --git a/stable/CMakeLists.txt b/stable/CMakeLists.txt
index e5c497a..ab481cf 100644
--- a/stable/CMakeLists.txt
+++ b/stable/CMakeLists.txt
@@ -78,6 +78,11 @@ if ( NOT BUILD_DYNAMIPS_STABLE )
    return ()
 endif ( NOT BUILD_DYNAMIPS_STABLE )

+# set MAC64HACK on stable OSX amd64 build
+if ( APPLE AND "amd64" STREQUAL "${DYNAMIPS_ARCH}" )
+   add_definitions( "-DMAC64HACK" )
+endif()
+
 # dynamips_*_stable
 set ( _files
    "${COMMON}/mempool.c"

Now the unstable build starts successfully, I haven't done any further tests.

The stable OS X 64 build shows:

C3725 'default': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH% No memory map for code execution at 0x0
% Unable to create instruction block for vaddr=0x0
insn_page_compile: unable to create JIT block.
VM 'default': unable to compile block for CPU0 PC=0x0

Doesn't look good for me, but it's the same with 0.2.12, so they are at least bug compatible.

grossmj commented 9 years ago

@ehlers excellent finding! looks like the Mac OS people will finally get the latest version of Dynamips ;)

julien-duponchelle commented 9 years ago

I just merge your patch thanks! I confirm it's work