Chapter 11 Software Development HP-UX Handbook Revision 13.
Chapter 11 Software Development October 29, 2013 TERMS OF USE AND LEGAL RESTRICTIONS FOR THE HP-UX RECOVERY HANDBOOK ATTENTION: PLEASE READ THESE TERMS CAREFULLY BEFORE USING THE HP-UX HANDBOOK. USING THESE MATERIALS INDICATES THAT YOU ACCEPT THESE TERMS. IF YOU DO NOT ACCEPT THESE TERMS, DO NOT USE THE HP-UX HANDBOOK. THE HP-UX HANDBOOK HAS BEEN COMPILED FROM THE NOTES OF HP ENGINEERS AND CONTAINS HP CONFIDENTIAL INFORMATION.
Chapter 11 Software Development October 29, 2013 TABLE OF CONTENTS Preface __________________________________________________________________________ 4 The Build Process __________________________________________________________________ 4 Source Code ____________________________________________________________________________5 Compiling ______________________________________________________________________________7 Objects ________________________________________________________________________________9
Chapter 11 Software Development October 29, 2013 Preface This chapter is intended to give an overview over issues on software development in general, and on HP-UX in particular. It is not intended to teach programming languages, and if at all, only basic skills in programming languages, and probably a little shell programming know-how are required to understand its contents.
Chapter 11 Software Development October 29, 2013 By default, the front-ends will execute all necessary build steps to create an executable from the input files passed to it. In the simplest case the build command to create a program from a source file is: -o
Chapter 11 Software Development October 29, 2013 This is a declaration of a function named main which takes no argument and returns a value of type int. To create the symbol a definition is required: int main() { : /* function code */ : } The definition of a function contains the function body. It must specify the same arguments and return code as the declaration. A symbol definition implies the declaration, so if there is a symbol definition in a source, no separate declaration is required.
Chapter 11 Software Development October 29, 2013 You might wonder where this stdio.h file can be found. This is one of the header files that are provided with the operating system, because it provides the declarations of symbols that are commonly used by a lot of programs. These files are collected inside the default path for system header files, /usr/include. The compiler frontend knows this default path so we don't need to care for it.
Chapter 11 Software Development October 29, 2013 Compiling The .i file is then passed to the compiler which translates the source code into machine code, creates a table of contents and references and stores both in an object file.
Chapter 11 Software Development October 29, 2013 $ cc -c -v HelloWorld.c /opt/aCC/lbin/ecom -architecture 32 -ia64abi all -ext on -lang c –exception off -sysdir /usr/include -inline_power 1 -link_type dynamic -fpeval float -fpevaldec _Decimal32 -tls_dyn on -target_os 11.
Chapter 11 Software Development October 29, 2013 On IA: Symbols from HelloWorld.o: [Index] Value Size Type Bind O Shndx Name [0] | 0| 0|NOTYP|LOCAL|0| UNDEF| [8] | 0| 0|SECT |LOCAL|0|.HP.opt_annot|.HP.opt_annot [7] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info [3] | 0| 0|SECT |LOCAL|0|.debug_actual|.debug_actual [2] | 0| 0|SECT |LOCAL|0|.debug_line|.debug_line [6] | 0| 0|SECT |LOCAL|0|.debug_procs_abbrev|.debug_procs_abbrev [4] | 0| 0|SECT |LOCAL|0| .rodata|.
Chapter 11 Software Development October 29, 2013 Symbols from HelloWorld.o: [Index] Value Size Type Bind O Shndx [0] | 0| 0|NOTYP|LOCAL|0| [8] | 0| 0|SECT |LOCAL|0|.HP.opt_annot|.HP.opt_annot [7] | 0| 0|SECT |LOCAL|0|.IA_64.unwind_info|.IA_64.unwind_info [3] | 0| 0|SECT |LOCAL|0|.debug_actual|.debug_actual [2] | 0| 0|SECT |LOCAL|0|.debug_line|.debug_line [6] | 0| 0|SECT |LOCAL|0|.debug_procs_abbrev|.debug_procs_abbrev [4] | 0| 0|SECT |LOCAL|0| .rodata|.
Chapter 11 Software Development October 29, 2013 Symbols from x.o: Name Value sub__Fc sub__Fi $ On IA: Symbols from x.o: [Index] : [5] [4] [11] [10] [1] | | Type Subspace 12|extern|entry 0|extern|entry Value | | | | | Scope Size 0| 0| 0| 0| 0| Type 0|SECT 0|SECT 32|FUNC 32|FUNC 0|FILE Bind |$CODE$ |$CODE$ O Shndx |LOCAL|0| |LOCAL|0| |GLOB |0| |GLOB |0| |LOCAL|0| Name .text|.text .text|.text .text|_Z3subc .text|_Z3subi ABS|x.
Chapter 11 Software Development October 29, 2013 On IA: $ c++filt _Z3subc _Z3subi sub(char) sub(int) $ nm++(1) is a script that calls nm(1) internally and uses c++filt(1) to demangle the mangled names in its output. Java and aC++ on HP-UX use the same name mangling algorithm, so c++filt(1) can also be used to demangle java method names. Linking The purpose of the linker is to create an executable file from a number of objects.
Chapter 11 Software Development October 29, 2013 object file a.o: Linker: executable file: exported symbols: - A (code) - load objects - link static parts - build symbol tables - search imported symbols in the libraries exported symbols: - A (code) - B (code) imported symbols: - B (code) - C (code) code of function A object file b.o: exported symbols: - B (code) imported symbols: - C (code) shared library list: - libXYZ.
Chapter 11 Software Development October 29, 2013 Because the linker creates the program file or the shared library, it also gives it its name. If nothing else is specified, the name will be a.out. A different name can be selected with the -o linker option. Every compiler frontend also knows this option, and if it is specified at the command line, it is passed to the linker. Linking HelloWorld It is always recommended to use a compiler frontend to link. We simply pass HelloWorld.o to cc.
Chapter 11 Software Development October 29, 2013 Also, on IA, the type of executable the compiler creates is either ELF-32 or ELF-64 IA. Either of these types is incompatible with files of type PA-RISC1.1 or PA-RISC2.0 (both are 32-bit) or ELF-64 PA (64-bit). Building shared Libraries One major difference between an executable and a shared library is that at runtime the executable will always be loaded to the same virtual address 0x0, while shared libraries must be loadable at any virtual address.
Chapter 11 Software Development main : printf printf : October 29, 2013 | 10400|extern|code |$CODE$ | | |undef |code 10384|uext |stub | | On IA: Symbols from HelloWorld: [Index] : [59] [42] $ Value | | Size 67110992| 270842400| Type Bind O Shndx 112|FUNC |GLOB |0| 0|FUNC |WEAK |0| Name .text|main UNDEF|printf nm(1) shows a lot of symbols in the executable. Most of them are from crt0.o. The interesting ones from the programmer’s point of view are main and printf.
Chapter 11 Software Development October 29, 2013 lazy swap allocation disabled text segment locking disabled data segment locking disabled third quadrant private data space disabled fourth quadrant private data space disabled data page size: D (default) instruction page size: D (default) nulptr references disabled On IA: HelloWorld: 32-bit ELF executable shared library dynamic path search: LD_LIBRARY_PATH enabled first SHLIB_PATH enabled second embedded path enabled third /usr/lib/hpux32:/opt/langtools/l
Chapter 11 Software Development Name Value : printf printf : | | Scope Type 959288|extern|entry 959328|extern|code October 29, 2013 Subspace | |$CODE$ On IA: Symbols from /usr/lib/hpux32/libc.so.1: [Index] : [3318] : Value | Size 268808160| Type Bind O Shndx 896|FUNC |WEAK |0| Name .text|fprintf On PA, we find printf as exported symbol, just as we found main exported in HelloWorld. On IA, we find printf as a .text symbol, just as we found main in HelloWorld.
Chapter 11 Software Development October 29, 2013 $ chatr HelloWorld HelloWorld: shared executable static branch prediction disabled executable from stack: D (default) kernel assisted branch prediction enabled lazy swap allocation disabled text segment locking disabled data segment locking disabled third quadrant private data space disabled fourth quadrant private data space disabled data page size: D (default) instruction page size: D (default) nulptr references disabled $ There are no library search pa
Chapter 11 Software Development October 29, 2013 Program Execution Besides the things the programmer has written, there are several other things that need to be done in a program. A program life cycle consists of the following steps: Load the Program Load shared libraries Resolve symbols Execute main() Terminate the program Processes are not allowed to access system resources like files, devices or the network directly.
Chapter 11 Software Development October 29, 2013 pread(3, "7fE L F 0102010101\0\0\0\0\0\0\0".., 1024, 0) .. = 1024 mmap(NULL, 2985888, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_SHLIB, 3, 0) = 0xc01e4000 madvise(0xc01e4000, 0x2d8fa0, MADV_NORMAL) ............... = 0 mmap(NULL, 47784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_SHLIB, 1, 0) = 0x797f0000 mmap(0x797e8000, 29796, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_SHLIB, 3, 3014656) = 0x797e8000 close(3) .................................................
Chapter 11 Software Development October 29, 2013 Load the Program Starting a program usually consists of two steps. First, a new process is created. This is called forking. The new process is called the child, the other one is the parent process. After forking, both processes are identical except of the process ID (PID), which must be unique on the whole system.
Chapter 11 Software Development October 29, 2013 Loading The Dynamic Loader As mentioned in the linking section of the previous chapter, every executable starts with the same object, crt0.o. It contains the startup code that is necessary to invoke the dynamic loader, which is itself a shared library. The path to the dynamic loader is the same as the default path for shared libraries, and is hardcoded into crt0.o: Executable Type Path of the Dynamic Loader PA-RISC 32-bit /usr/lib/dld.
Chapter 11 Software Development October 29, 2013 $ chatr /usr/lib/hpux32/libc.so.1 : shared library list: libdl.so.1 : The ldd(1) tool can be used to list all libraries used by a program, without starting it, in the order they were loaded if the program was started.
Chapter 11 Software Development October 29, 2013 exported symbols: - printf exported symbols: - printf imported symbols: - main (unresolved) - shl_load (unresolved) imported symbols: - main (resolved) - shl_load (unresolved) library list: - libdl.so.1 library list: - libdl.so.1 libc.so.1 introduces new imported symbols, e.g. main and shl_load. The former can be resolved from HelloWorld, but the latter is not there yet. libc.so.1 has libdl.so.
Chapter 11 Software Development October 29, 2013 If there were no more libraries to load, but there were still symbols that could not be bound to an address (could not be resolved), an error would be reported and the program would abort. Execute main() After the libraries are loaded and all symbols could be resolved, main() is called to execute the code the program was written for. HelloWorld was written to print the text "Hello World!". The required system calls are: ioctl(1, TCGETA, 0x7dff0f30) ......
Chapter 11 Software Development October 29, 2013 On HP-UX 10.X there were only user threads (also referred to as 1xN), which means that the kernel has only one thread per process, but the program can handle multiple threads, and it is up to the process to determine which of its threads should run.
Chapter 11 Software Development October 29, 2013 calling exit() calling exec() receiving a signal that causes abnormal termination. If a process aborts with a coredump, the core file will always be written to the working directory of the process. Although we do not call exit() explicitly in the HelloWorld.c source code, the system call exit() is called automatically after reaching the end of main(), to terminate the process normally: exit(13) .........................................
Chapter 11 Software Development October 29, 2013 Usually no program has as much code to fill the whole quadrant, so it only uses the beginning of the quadrant, the rest of its address range will not be is used. All data in the first quadrant is readonly. A process is not allowed to modify its code, because HP-UX will share one instance of the program code if multiple processes are running the same program. Q2 holds the private data of the process.
Chapter 11 Software Development October 29, 2013 Process Private Memory A process has three methods to store private data. It can store it on the process heap, save it on the stack, or in privately mapped regions. All three methods use the second quadrant, as it is the only quadrant for private memory, but they follow different allocation rules. Every program has heap and stack, but it will only have mapped regions if it explicitly creates them. The heap starts at the beginning of Q2.
Chapter 11 Software Development October 29, 2013 Shared Memory As the name implies, data in the shared quadrants is shared between processes. There are two types of shared memory on HP-UX, System V shared memory (shmget(2), shmat(2) etc.) and shared mappings (mmap(2) with the MAP_SHARED attribute). Shared library text is made available to processes using shared mappings.
Chapter 11 Software Development October 29, 2013 No such limits exist for shared mappings, but of course there is still the address space limit. The third and fourth quadrants are dedicated to shared data and text, and the size of both quadrants, reduced by ca. 250 MB in Q4 which are reserved for the kernel, is the only limit. But this is a system wide limit. If the shared quadrants are full, they are full for all processes on the system.
Chapter 11 Software Development October 29, 2013 Allowing Private Data In Q3 and Q4 The chatr(1) command can be used to enable private data in the third and fourth quadrant: chatr [ +q3p enable|disable ] [ +q4p enable|disable ] prog chatr +as mpas prog ### PA-RISC ### Itanium This can be done independently of the Q1 usage, it is possible for both SHARE_MAGIC and EXEC_MAGIC executables. No relink is required for this change. This feature is called “Large Data Space”. On HP-UX 11.
Chapter 11 Software Development T e Heap x t Heap heap October 29, 2013 s t una Heap used c *1 k s h l i b s h l i b shlib: shared library *1: can be used to increase the heap, for additional shared libraries or to map regions Remember that maxdsiz and ulimit must be set high enough. Of course the amount of memory a process can allocate is also limited by the amount of virtual memory (swap space). So if there is not enough available, all these techniques are useless.
Chapter 11 Software Development October 29, 2013 Types Of Executables The usage of the quadrants Q1 and Q2 define the type of an executable.
Chapter 11 Software Development October 29, 2013 Products On HP-UX There are a lot of different high level programming languages. Most of them are grown historically and have a focus on certain types of applications. The following list shows the most commonly used languages and their focus: Language C C++ Fortran Java Focus system programming object oriented, technical programming numerical calculations server applications, platform independent URL http://www.hp.com/go/c http://www.hp.
Chapter 11 Software Development October 29, 2013 Java is discussed separately because it is different from conventional languages in several ways. Development Tools HP Compilers HP provides compilers for all commonly used programming languages.
Chapter 11 WDB-GUI Software Development October 29, 2013 GUI for the HP WDB Debugger WDB is the preferred debugger on HP-UX, and is based on the Gnu debugger gdb.
Chapter 11 Software Development October 29, 2013 Related Products All compiler frontends (including the bundled cc) use the same linker ( /usr/ccs/bin/ld) to create their executables. The linker is not part of any compiler. The same applies to many tools described in the tools section. Linker and linker tools are installed with HP-UX in the filesets OS-Core.C-KRN OS-Core.C-MIN OS-Core.
Chapter 11 Software Development October 29, 2013 Not listed here, but of course needed by any program that uses shared libraries, is dld.sl/.so. The dynamic loader is part of the linker filesets. For each HP-UX shared library there normally exist an archive version too (with the extension .a). These libraries do not belong to runtime environments because they only can be linked when a program is built. Nevertheless they are shipped with the runtime patches.
Chapter 11 Software Development October 29, 2013 Executing A java application must contain one class that provides a method (function) defined exactly as public static void main(String[] args), which is invoked to start the application. To execute a java program, the JVM must be started with the class or jar archive that contains this method as a command line parameter: java HelloWorld java -jar HelloWorld.jar Note that the .class extension of the class file must be omitted, while the .
Chapter 11 Software Development October 29, 2013 JDK and JRE are free. They can be installed from an application CD or downloaded from the java product page [1], which always holds the latest and previous releases. Java upgrades are not available as patches. New versions can always be downloaded from the above website as they become available. There is however a list of HP-UX patches that are recommended or even required for java. These are listed at http://ftp.hp.
Chapter 11 Software Development October 29, 2013 All shells know three operating modes. When calling a shell with an argument, it enters the automatic mode, which expects the argument to be a script. The shell interprets the script and if the script exits, the shell exits too. If no argument is given to the shell, it is started in interactive mode where it prints a command prompt and waits for user input.
Chapter 11 Software Development October 29, 2013 There is a special version of the POSIX shell available on HP-UX, /sbin/sh. It differs from /usr/bin/sh in the way it was linked. /sbin/sh is completely archive bound. It is strongly recommended to use it as the login shell of the root user because it doesn't need shared libraries for execution. If e.g. the file system /usr cannot be mounted, /sbin/sh is the only shell that will still work.
Chapter 11 Software Development October 29, 2013 The Key shell is an extension of the standard Korn-shell. It uses hierarchical softkey menus and context-sensitive help to aid users in building command-lines, combining the power of the Kornshell with the ease-of-use of a menu system. The Key-shell continually parses the command-line and always presents the user with an appropriate set of current choices on the softkey labels. At the bottom of the screen you can see the soft keys.
Chapter 11 Software Development October 29, 2013 The Interpreter Line Scripts cannot be executed directly by the system. They require an interpreter to read and execute the commands contained in the script. The regular way to execute a script is to pass the script name as an argument to its interpreter, e.g. $ /usr/bin/ksh myscript.sh But if the script file has execute permission, it can also be started by typing just the name of the script: $ ./myscript.sh This is a feature of exec(2).
Chapter 11 Software Development October 29, 2013 Tools The tools to look at in this workshop can be divided into three categories: 1. Development utilities 2. Tools for obtaining static information 3. Tools for runtime analysis In the Development Utilities section we will look at build process management and versioning tools. Static information is considered to be properties of files in general. These tools look into binary files to get information about versions, required libraries, symbols etc.
Chapter 11 Software Development October 29, 2013 make(1) As described in the Build Process, applications can consist of multiple executables and shared libraries. Each of them normally is built from multiple objects, and each object is built from multiple header and source files. If source files have changed, you could either rebuild the whole application, which could take very long, or you could just recompile and relink those parts that depend on the changed sources, thus saving a lot of time.
Chapter 11 Software Development -> obj_b.o -> -> October 29, 2013 mydefs.h obj_b.c myprog is the main target. It must be built (linked) from the objects obj_a.o and obj_b.o. The objects themselves are targets too, they must be built (compiled) from source and header files. A simple makefile to handle these dependencies could look like this: myprog: obj_a.o obj_b.o cc -o myprog obj_a.o obj_b.o obj_a.o: mydefs.h obj_a.c cc -c obj_a.c obj_b.o: mydefs.h obj_b.c cc -c obj_b.
Chapter 11 Software Development October 29, 2013 Static Information file(1) The file(1) command tries to determine the type of a file by checking magic(4) numbers. On ascii files it analyzes the first lines and tries to guess a programming language, if any. If you have compiled a C program named a.out which was compiled from a source file named x.c, and which unfortunately aborted with a coredump, file(1) will give an output similar to the following: $ file x.c x.o a.out core On PA: x.
Chapter 11 Software Development October 29, 2013 $ what x.c x.o a.out core x.c: x.c version 0.1 from Jan 04 2002 x.o: x.c version 0.1 from Jan 04 2002 a.out: x.c version 0.1 from Jan 04 2002 core: x.c version 0.1 from Jan 04 2002 $ PATCH/11.00:PHCO_24723 Sep 13 2001 05:01:45 $ 92453-07 dld dld dld.sl B.11.30 011005 The core file contains some more what strings than just ours. These come from the shared libraries used by the program, in this case libc.sl and dld.sl (or on IA libc.so.
Chapter 11 Software Development October 29, 2013 SHLIB_PATH enabled second embedded path disabled first Not Defined shared library list: dynamic /mylib/libmine.sl dynamic /usr/lib/libc.2 : The embedded path list can only be defined at link time with the +b linker option, and is stored in the executable. The default path is where the library was found at link time. The linker stores it automatically in the executable. On IA64, dld.
Chapter 11 Software Development $ ldd a.out => /usr/lib/libc.2 => /usr/lib/libdld.2 => /usr/lib/libc.2 => October 29, 2013 /tmp/libc.2 /usr/lib/libdld.2 /tmp/libc.2 ldd(1) belongs to the linker tools. nm(1) This command displays symbol tables of objects, archives, executables and shared libraries. The output shows if a symbol is contained in the file or if it is referenced. See the objects and executables in the build section for nm(1) outputs.
Chapter 11 -verifyall Software Development October 29, 2013 Executes a series of tests on the file. This can be used to verify the general structure of the file. It prints error messages if internal structures are corrupted. For detailed explanation of the odump(1) outputs, refer to the man page for a.out(4). odump(1) can only be used with 32-bit PA-RISC objects. For 64-bit PA-RISC objects or IA64 objects elfdump(1) is an equivalent tool. odump(1) and elfdump(1) belong to the linker tools.
Chapter 11 Software Development October 29, 2013 gdb program [ core | PID ] It will print a startup message load the specified program. If a core file name is added, it will be loaded too, and the location of the program abort is printed. When adding a process ID, gdb(1) will attach to this process, stop it and print the location where it was stopped. Then the (gdb) prompt is printed to wait for user input. When debugging a core file, it is a good practice to give the core file another name than “core”.
Chapter 11 Software Development October 29, 2013 Starting program: /var/tmp/HelloWorld Breakpoint 1, main () at HelloWorld.c:4 4 printf("Hello World!\n"); (gdb) When invoking gdb, it loads the program but does not execute it yet. First we print out the source program to check where we are. Then we tell gdb to stop execution when entering main() by setting a breakpoint there, and run the program. gdb will stop execution at the first executable statement of main().
Chapter 11 Software Development October 29, 2013 Breakpoint 2, 0x7f7a5378 in printf () from /usr/lib/libc.2 (gdb) Remember that printf(3S) is in libc which has no debug info. That's why gdb can only determine the code address of the breakpoint, and not the source file and line number. When rerunning the program, it stops again in main() because gdb keeps breakpoints until they are unset, another program is loaded or gdb exits. After continuing, gdb stops the program at the first instruction of printf().
Chapter 11 Software Development October 29, 2013 (gdb) c Continuing. Hello World! Program exited with code 013. warning: Temporarily disabling shared library breakpoints: warning: breakpoint #2 (gdb) quit $ After continuing, the program it exits as before. We leave gdb by typing quit or simply q. When debugging a program that died on another system, it is not sufficient to take program and core file and start debugging.
Chapter 11 Software Development October 29, 2013 For example if core files should be stored in a separate file system that provides sufficient disk space, and their names should contain program name and PID of the aborted process, the following command can be used (as root): # coreadm –e global –g /core files/core.%f.%p tusc While a debugger is helpful to analyze what happens inside a running program, it often is interesting to see how a program interacts with the kernel.
Chapter 11 Software Development October 29, 2013 The open() system call shows that the process opened the file "/tmp/xyz" for reading and writing. The third argument is undocumented in the manpage. This is such a difference between the system call and the libc function. The return value 3 is a reference number to be used for subsequent system calls to access this file. This number is called the file descriptor. write() used this file descriptor and sent 13 bytes to the file.
Chapter 11 MMAP MMAP SHLDATA STACK SHLTEXT SHLTEXT : Software Development 0xd22f400.0x000000006ffe6000 0xd22f400.0x000000006ffea000 0xd22f400.0x000000006ffec000 0xd22f400.0x000000006fff0000 0x7082400.0x00000000c0004000 0x7082400.0x00000000c0010000 1 1 1 1 109 117 October 29, 2013 4 2 4 528 3 33 3 2 4 272 3 33 5 3 5 530 1 1 kmeminfo prints one line for each memory region. Most interesting are columns 1, 3 and 5. Column 1 tells what the region is used for. The abbreviations are self-explaining.
Chapter 11 Software Development October 29, 2013 adb(1) is part of the OS-Core commands. lsof lsof is a tool that displays information about open file descriptors on a system, including pipes and networking connections, plus the loaded shared libraries. It queries the kernel for that information. To find out the files opened by a certain process you can either filter the output, e.g. using grep(1), or use the -p option. To see all processes that have file open, run lsof .
Chapter 11 Software Development October 29, 2013 Solving Common Problems Software development is is a very wide field, and there are not many common problems that have standard solutions. Unlike in other areas, the products described here do not require complex configurations nor are there general rules for their usage. There are however a few standard situations that allow a common approach. This chapter is under continuous construction and therefore can not be viewed as complete.
Chapter 11 Software Development October 29, 2013 Normally there are no known problems installing these products. Upgrading them is done with patches. Every patch can be installed on a base HP-UX installation, but might have dependencies. The second category of products is also free but must be installed separately: Java Perl wdb/gdb debugger The products can be downloaded from the web. There are no patches available for these products.
Chapter 11 Software Development October 29, 2013 $ /usr/sbin/swlist | grep -e B3911 -e B3913 B3911DB C.03.27 HP aC++ Compiler (S700) $ At this 11.11 system we have installed version A.03.27. At the time of this writing, the latest version for 11.11 is A.03.85. To upgrade to the latest version we need to install the A.03.85 base release from the September 2008 application CD/DVD.
Chapter 11 Software Development October 29, 2013 Build Problems Normally every build process should succeed without any message from the compiler or the linker. Messages should never be ignored, even if the build process succeeds, because they could lead to runtime problems. Solving most of the build problems means to understand compiler and linker messages and to take appropriate actions like code changes, different compiler or linker options etc. to remove the reasons for the messages.
Chapter 11 Software Development October 29, 2013 In the makefile "xxx" was specified as a dependent, but neither does the file exist nor was there a rule to build it. The writer of the makefile must check if this file is really needed to build the targets. If not, remove the file from your dependents. If yes, get a copy for make(1) to find or find out how to create it and add a rule to the makefile to create it. PA2.0 Warning /usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (x.o) was detected.
Chapter 11 Software Development October 29, 2013 The symbol is indeed missing: You checked all objects and libraries with nm(1) but there were only references (undef). Check if there is a library or an object missing in the link command. Use nm(1) to find it. To find out if a symbol is in an HP-UX runtime library, you could also check if there is a man page available for it. If there is one, it sometimes tells you which library must be used.
Chapter 11 Software Development October 29, 2013 /usr/ccs/bin/ld: Unsatisfied symbols: Iostream_init::~Iostream_init() (first referenced in x.o) (code) Iostream_init::Iostream_init()%1 (first referenced in x.o) (code) : This is the inverse case. There was at least one object compiled without -AA, but it was linked with this option. Again, make sure that either -AA is always used, or never.
Chapter 11 Software Development October 29, 2013 Compiler/Linker Aborts Besides the problems described above, which are typically user errors, it also can happen that a compilation/link aborts because of internal errors. Compilers as well as the linker can abort if there is not enough memory available to build the program. Possible error messages that indicate such a problem are: Error 8203: Exact position unknown; near ["/usr/include/errno.h", line 32].
Chapter 11 Software Development October 29, 2013 Problems Starting A Program There are a few reasons why a shell cannot execute a program. The most obvious is that the program file has no execute permission. The different shells then give a self-explaining message. Another reason is that the file has an incorrect magic number. The magic number determines the type of a file, and the system can tell by the magic number if the file contains executable code or not. ksh: ./a.
Chapter 11 Software Development October 29, 2013 message and terminate the program. On PA-RISC it uses abort(3C) which causes a coredump to be written. A core file analysis is in such a case normally not required, because the error message should explain what happened. But the core file is not totally useless, because the dld message does not print the name of the program that had a problem.
Chapter 11 Software Development October 29, 2013 this product is not installed. Other paths might have been available only on the system where your program has been developed. If the library exists in a different path than the ones searched, point the environment variables SHLIB_PATH or LD_LIBRARY_PATH to it. In any case of uncertainty, ask the vendor of the program from where to get the library and in which path to store it. Symbol Resolution Problems /usr/lib/dld.sl: Unresolved symbol: x (code) from .
Chapter 11 Software Development October 29, 2013 Exec Format Error /usr/lib/dld.sl: Bad magic number for shared library: ./libmylib.sl /usr/lib/dld.sl: Exec format error Abort(coredump) /usr/lib/dld.sl: Bad system id for shared library: ./libx.sl /usr/lib/dld.sl: Exec format error ABORT instruction (core dumped) These or similar errors messages appear if the dynamic loader tries to load a shared library of an executable format which is incompatible either to the executable or to the hardware.
Chapter 11 Software Development October 29, 2013 Program Aborts There can be an infinite number of reasons why a program aborts abnormally. We can distinguish between two types of aborts: The program encounters an error situation and stops by its own means. In this case it should print an (hopefully self-explaining) error message. The system (the kernel) encounters an error while executing the program, and aborts it by sending it a signal.
Chapter 11 Software Development October 29, 2013 x.c version 0.1 from Jan 04 2002 $ PATCH/11.00:PHCO_24723 Sep 13 2001 05:01:45 $ 92453-07 dld dld dld.sl B.11.30 011005 $ If the what(1) output does not end with the what string of dld/dl, the core file is incomplete and can’t be used for debugging. A core file size of 2147483646 (2 GB - 2 Bytes) indicates a missing largefiles option of the target file system.
Chapter 11 Software Development October 29, 2013 # echo core_addpid/W 0 | adb -w /stand/vmunix /dev/kmem On HP-UX 11.31 and later, coreadm(1M) can be used by any user to define the name of the core files created by his processes, e.g. $ coreadm –p core.%p Will instruct the kernel to store all core files of this user as core.. The reasons for not getting a core file can be: The process has no write permissions in its working directory.
Chapter 11 Software Development October 29, 2013 # echo dump_all/W 0 | adb -w /stand/vmunix /dev/kmem This flag will not be stored permanently. The setting will be lost after a reboot. Programs which catch fatal signals that would otherwise cause an abort with core dump, should provide at least basic information like stacktraces before they exit.
Chapter 11 Software Development October 29, 2013 (gdb) thread 1 [Current thread is already 1 (system thread 3785)] (gdb) bt Thread 1 (system thread 10567): #0 0x7efa5cac in printf+0x18 () from /usr/lib/libc.2 #1 0x29f0 in main () at x.c:4 (gdb) The interesting thread is the one marked with an asterisk in the threads listing. See the section about gdb(1) on how to read the stacktrace.
Chapter 11 Software Development brk(2): process heap (private) mmap(2): memory mapped regions (private or shared) shmget(2): System V shared memory October 29, 2013 If we don’t know how the process makes use of its address space, we can either use tusc(1) to check which of the above system calls it executes, or look at the current usage of the process address space with kmeminfo or glance(1).
Chapter 11 : type TEXT DATA MMAP : STACK : Software Development October 29, 2013 space vaddr 0xb288800.0x0000000000001000 0x15a6400.0x0000000040001000 0x15a6400.0x0000000072b90000 ref 3 1 1 virt 5 1023 13 phys 5 766 13 swap 1 1026 14 0x15a6400.0x000000007dff0000 1 528 272 530 $ The DATA line describes the heap. Its start address is given in the vaddr column, and its size in 4k pages in the virt column.
Chapter 11 Software Development October 29, 2013 Memory Leaks If process memory hits a system limit despite having it already increased to a reasonable value, the process is likely to have a memory leak, which means it allocates memory but fails to free it when it is no longer needed. In this case, further increasing the limits will only result in the program taking longer until the limit is hit, but the problem is not gone.
tack Chapter 11 Software Development October 29, 2013 Stack Overflow In the process memory section we learned that the stack holds a lot of important information for the program flow. A stack overflow or corruption will normally cause the process to abort with a signal and leave a core file, but debugging such a core file can become very hard, because the debugger might not be able to recover the program flow information. In that case you cannot even get a valid stacktrace from the core file.
Chapter 11 Software Development October 29, 2013 On Itanium the stack works a bit differently. While on PA-RISC the stack holds both register contents and local variables mixed together in the same area, the Itanium architecture splits the stack region into 2 parts and separates the register contents from other local variables. The register stack starts at the lower end of the stack region and grows upwards, while the normal stack starts at the upper end and grows downwards.
Chapter 11 Software Development October 29, 2013 smaller than the primordial thread, that’s why stack overflows are much more likely in multithreaded programs. These default sizes are hardcoded into the POSIX threads library libpthread[.sl|.so]. Programs can specify the stacksize for each new thread before it is created with pthread_attr_setstacksize(3T). Alternatively they can also change the default stacksize with pthread_default_stacksize_np(3T) before they start creating threads.
Chapter 11 MMF: MMF: : $ Software Development b = 7360B000 e = 7368C000 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ b = 7368C000 e = 7370D000 October 29, 2013 f = 9B7A0C4 f = 9BFB0D4 In the above case the stack pointer is close to the start of the highlighted MMF region, that means only a tiny bit of the thread stack was used and we were far away from a stack overflow.
Chapter 11 Software Development October 29, 2013 This is even harder to track down than unchecked allocation failures, because again the abort does not occur when overwriting the heap structures, but only on one of the next calls to malloc() or free(). Also, the overwriting could have happened everywhere in the code, whenever the program accesses the heap. There is no special function call to look for. WDB’s heap checking features can help here.
Chapter 11 Software Development October 29, 2013 (gdb) r rerun the program The program being debugged has been started already. Start it from the beginning? (y or n) y warning: Temporarily disabling or deleting shared library breakpoints: warning: Deleting breakpoint #-50 warning: Deleting breakpoint #-51 Starting program: /space/mstreibe/cases/heap/a.out 1234567890 warning: Watched address 0x4042c448 allocated __rtc_event () at ../../../Src/gnu/gdb/infrtc.c:699 699 ../../../Src/gnu/gdb/infrtc.
Chapter 11 Software Development October 29, 2013 Java Abort If the JVM aborts, it will always try to leave a core file. Depending on the java version and the reason of the abort, it sometimes writes additional information into a file named hs_err_pid.log, where is the process ID of the aborted java process. When looking at a java core file, make sure to use the correct java executable. /opt/java1.4/bin/java is not the real java executable. It is only a wrapper. The correct java executables, e.
Chapter 11 Software Development October 29, 2013 (gdb) bt #0 0xc020a6d0 in kill+0x10 () from /usr/lib/libc.2 #1 0xc01a55cc in raise+0x24 () from /usr/lib/libc.2 #2 0xc01e59b0 in abort_C+0x160 () from /usr/lib/libc.2 #3 0xc01e5a0c in abort+0x1c () from /usr/lib/libc.2 #4 0xc455d468 in abort__2osSFb+0x108 () from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl #5 0xc441f834 in report_error+0x5b4 () from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl #6 0xc441ef8c in report_fatal+0x6c () from /opt/java1.
Chapter 11 Software Development October 29, 2013 #7 0xc47a9a0c in compute_compiled_exc_handler+0x1e4 () from /opt/java1 .4/jre/lib/PA_RISC2.0/server/libjvm.sl #8 0xc47a9698 in handle_exception_C__11OptoRuntimeSFP10JavaThread+0x14 8 () from /opt/java1.4/jre/lib/PA_RISC2.0/server/libjvm.sl #9 0x78f18108 in ?? () Java Out Of Memory Of course, for java the same rules apply as for all other processes running out of memory.
Chapter 11 Software Development October 29, 2013 The new generation heap. New objects are created here. The new space is divided into 2 parts: o The eden space. o The survivor space is again divided into 2 parts: from space to space The old or tenured generation heap. Long lived objects will be moved to here. The permanent generation heap. Java class information is stored here.
Chapter 11 Software Development October 29, 2013 also be done with HPjmeter. An excellent document about this and other tasks is the java troubleshooting guide at http://h18012.www1.hp.com/java/support/troubleshooting_guide.html An out of memory condition in the process heap can be treated the same way as an out of memory for any other process. The JVM might have hit maxdsiz or ulimit -d while trying to increase the process heap.
Chapter 11 java_q4p Software Development > 2400m text + private data October 29, 2013 private private private 4 GB The IA64 platform knows another address space model, which is used by the JVM for applications that need a large java heap.
Chapter 11 Software Development October 29, 2013 reduced stacksize of 508k, both stack and guard page will fit into 2x 256k, and the mapping will occupy exactly 512k, with nothing wasted. The java heap size (-Xmx option) might need to be adjusted to reflect the real requirements of the java application. A too large java heap wastes address space at the expense of the JVM. The required heap sizes can be found by analyzing GC logs with HPjmeter. In some cases it might help to increase the java heap. E.g.
Chapter 11 Software Development October 29, 2013 Compiler Related Variables Every HP compiler knows a specific environment variable that is read by the compiler frontend to allow specifying additional command line parameters without making changes to the command line itself. The contents of this variable are handled as if they were passed to the compiler on the command line.
Chapter 11 Software Development October 29, 2013 Linker Related Variables In fact, there is only one environment variable for the linker, LDOPTS. It has the same function as the compiler variables, and it also works in the same way. Runtime Related Variables Of course, it is totally left to the programmer to determine which environment variables his program reads, if any. But because every program uses dld.
Chapter 11 Software Development October 29, 2013 There is also a related environment variable called LD_PRELOAD_ONCE. The LD_PRELOAD_ONCE feature is similar to LD_PRELOAD except that the dynamic loader, dld.so, unsets LD_PRELOAD_ONCE after reading it, so that any applications invoked by the current application do not have LD_PRELOAD_ONCE set.
Chapter 11 Software Development October 29, 2013 Additional Information HP provides lots of information to software development on its websites at hp.com. But as always, the larger the amount of information available, the harder is it to find something on a specific topic. This chapter lists the most important links that lead to software development related pages on the HP website as well as on other resources.
Chapter 11 Software Development October 29, 2013 HP Internal Links [7] http://wtec.cup.hp.com/~/ These are the homepages of the WTEC teams. The most relevant team names are: o Languages WTEC: lang o HP-UX WTEC: hpux o Graphics WTEC: xgraph These pages provide information to all supported products and other valuable information. [8] http://ktools.france.hp.com/~ktools/cgi-bin/downloads.cgi The KTOOLS Website that provides latest versions of helpful tools like tusc, kmeminfo etc.