Sunday, April 11, 2010

X Forwarding

You can use a file on a remote Unix machine as if it were on your local machine. This is useful for reading PDF documents you left on your desktop at school and don't want to scp to home. To do it use the command:

ssh -X anisbet@ohaton.cs.ualberta.ca

After you have authenticated and are sitting at the command prompt on the remote machine, run the desired application on the remote machine's command line like this:

anisbet@ohaton:~>xpdf test/report.pdf

The document will open using the local version of xpdf, (it must exist on the local machine to work, and remote machine aswell) but will display the remote document.

Friday, April 9, 2010

Core Dump

You can make an application core dump if you use the Unix command:

ulimit -c unlimited

Will dump when an application seg faults. The default setting was '0'. A core file is basically a file which contains the complete state of the process when it crashed. To determine where the problem occurred, run gdb:

gdb

Then run

(gdb) core [app_name.]core

Then use the gdb command 'bt' to back trace.

Compiling with g++ version 4.1.1, and the -g switch I still didn't get anything very 'trace-able', so I had to bite the bullet and try running the application from within gdb. Easy you say, but this application takes its input from another application on STDIN. To do that with my application (called a4vmsim):


gdb a4vmsim
(gdb) run params ... < input.txt


And that did the trick! I got the following output:

Program received signal SIGSEGV, Segmentation fault.
0x0804c004 in Page::setReferenceFlag (this=0x80540b8) at page.h:23
23 void setReferenceFlag(void){ flags |= REF_BIT; }


Using back trace:

(gdb) bt
#0 0x0804c004 in Page::setReferenceFlag (this=0x80540b8) at page.h:23
#1 0x4804d57b in ?? ()
#2 0x0804a2ee in MemoryManagementUnit::referencePage (this=0x80540a8, page=158) at mmu.cpp:66
#3 0x080494d7 in Simulator::process (this=0xbffff33c, instruction=158) at sim.cpp:79
#4 0x0804945a in Simulator::runSimulation (this=0xbffff33c, in=...) at sim.cpp:58
#5 0x08049219 in main (argc=14, argv=0xbffff434) at app.cpp:27


Thursday, April 8, 2010

Conditional Compilation Between GCC Versions

In assignment 4 of 379 I had to use the deprecated hash_map data structure. It doesn't compile on ohaton because the GCC version is 4.2.1. In that version hash_map is in the include directory

#include <ext/hash_map>

and on my home machine (GCC 4.1.1) it is in

#include <hash_map>

To get the source to compile on both machines I used the following precompiler directives:

#if ( __GNUC__ == 4 && ( __GNUC_MINOR__ == 2 ) )
#include <ext/hash_map>
#else
#include <hash_map>
#endif

Note that if you need finer granularity there is also a __GNUC_PATCHLEVEL__ . So GCC version 4.2.1: __GNUC__ == 4, __GNUC_MINOR__ == 2 and __GNUC_PATCHLEVEL__ == 1.


This technique can also be used:

#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 
+ __GNUC_PATCHLEVEL__) 
 ...
 /* Test for GCC > 3.2.0 */ 
#if GCC_VERSION > 30200