1
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Using SCO-Provided Development and Programming Tools
Ron Record John Wolfe [email protected] [email protected]
2
Agenda
● Overview of SCO provided Development Systems● Suggested open source tools● Building open source applications
● Getting source, configuration and build issues● Debugging techniques
● truss, debug, dynamic memory debugging● FUR – function reorganizer● Packaging tools
● custom and pkgadd
3
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Review
OpenServer 6.0.0 Development System
4
How OpenServer 6 is Structured
OSR System Libs
/osr5/usr/lib/
OSR System Libs
/osr5/usr/lib/
SVR5/UDK System Libs
/usr/lib/
SVR5/UDK System Libs
/usr/lib/
OpenServer 6 dev tools
/usr/ccs/bin/
OpenServer 6 dev tools
/osr5/usr/ccs/bin/
One OpenServer 6 KernelOne OpenServer 6 Kernel
OSR5 sys callsOSR5 sys calls SVR5 sys callsSVR5 sys calls
OSRABI
SVR5/UDKABI
One OpenServer 6 User ExperienceInstall, desktop, sys admin, commands
One OpenServer 6 User ExperienceInstall, desktop, sys admin, commands
Legacy AppsLegacy Apps Modern AppsModern Apps
5
Application Binary Interface – What is that?
● What an app looks like at the binary level● content and layout of information that it presents to
system loaders and linkers (object file format)● How different modules of an app communicate
● function call conventions● size and layout of basic data types● size and layout of compound data types - structures,
unions, bit-fields● How an app communicates with the OS
● pathnames, sys call numbers, errno’s, ioctl's● size and layout of basic and aggregate system data
types
6
OpenServer 6 – SVR5 ABI - default
● OpenServer 6 Devsys for SVR5 (UDK) ABI● OpenServer 6 Devsys using -K udk option
● or - /usr/bin/cc which defaults to –K udk ● use for single certification on UnixWare 7 and
OpenServer 6● use for modernizing existing OSR5 apps● use for device driver development (IHVs)● used to relink the OpenServer 6.0.x SVR5 kernel● provides access to “NEW” features
● threads and LFS (> 2 Gbyte files)
7
OpenServer 6 – OSR ABI
● OpenServer 6 Devsys for OSR ABI● OpenServer 6 Devsys using -K osr option
● or /osr5/usr/bin/cc which defaults to –K osr● set PATH environment variable with /osr5/usr/bin before /bin,
/usr/bin or /usr/ccs/bin● use for binary compatibility to legacy OSR5 apps● provides more modern C and C++ compilers
● Standards Conformance (almost) C and C++● same level of code generation and optimization as in the
SVR5/UDK compilers● 64-bit “long long”
● NOT available - threads or large files (> 2 Gbytes)
8
Mixing OSR and UDK ABI Object Files
● No safe way to link OSR5 ABI and SVR5/UDK ABI relocatable or shared objects (.o/.a/.so)
● no way to intercept different system data types● no way to intercept different bit-field layouts and
function calling conventions● no way to intercept system calls from objects
● Linker will reject mixture of objects, by default● Force link mode provided - “I know what I’m
doing”● but you probably don’t● not recommended
9
Building Legacy OpenServer 5 Apps
● When is OSR ABI needed?● when linking with existing OSR5 .o/.a/.so objects
● Use OSR ABI compilers● same as UDK but with -Kosr for OSR ABI● modern, reliable, standard, optimizing● 64-bit “long long” integer available● LFS, threads and EFT not available● can accept OSR5 COFF objects as input to linker
● but cannot generate COFF● can link with existing OSR5 C .o/.a/.so objects
● but cannot link with existing OSR5 C++ objects● use CC -Xo to compile very old OSR5 C++ sources
10
Want new features but need compatibility with old OSR5 library?
● If your own, recompile
● If from another ISV, get vendor to provide new, SVR5 ABI-built libraries
● If neither is possible ...● make app into 2 processes● one process calls old lib
● compile -Kosr
● one process uses new features ● compile -Kudk
● use socket, pipe, IPC, etc. to communicate between processes
11
Guidance on modernizing existing apps: Threads
● Must modify to use threads● pthreads API more standard than SVR4/UI threads● use -Kudk to recompile application● use -Kpthread when compiling threaded code
● fixes some things like global errno automatically
● Existing OSR5 source may not be thread-safe!● may use non-reentrant functions such as strtok()
● use <name>_r() replacements when available● may store application data globally● may return pointers to static data● must study your code
12
Guidance on modernizing existing apps: Large files
● Go forward with Large File Summit (LFS) APIs● use -Kudk to recompile application● create files up to one terabyte in size● can use size-specific interfaces
● fopen64, lseek64, etc.● or, can use regular fopen, lseek, etc.
● cc -D_FILE_OFFSET_BITS=64● off_t, etc. become 64 bits
● must use vxfs filesystem and create filesystem with largefiles flag● mkfs or fsadm_vxfs to turn on/off
● ulimit must be set to unlimited
13
Guidance on modernizing existing apps: Fundamental system types
● Be careful with expanded fundamental system types (EFT)
● Size change between OSR5 and OSR6 in UDK mode:● mode_t, dev_t, uid_t, gid_t, nlink_t, pid_t, ino_t, sigset_t● typically size goes from 16 bits to 32 bits ● system or app struct’s containing them also change size
● e.g., struct stat contains both dev_t and ino_t● dev_t also changes how major, minor numbers packed● all consequences of SVR5 infusion into OpenServer 6 kernel
● Change should be transparent unless your code has assumptions about size
14
Guidance on modernizing existing apps: C++
● Existing OSR5 DevSys C++ compiler is old!● AT&T Cfront-based, c. 1992, buggy● predates 1998 ISO language/library standards● large-scale changes in language since then
● If your sources were developed with it …
● expect they will not compile cleanly now● source fix-ups are usually straight forward
● you’re doing your code a favor!● for bad cases try the CC -Xo option● old library classes will all still be there
15
Guidance on modernizing existing apps: C++ ABI issues
● C++ ABIs are unique for each compiler● Exception handling implementation● Class object layout
● Virtual function table pointer position● Base class sub-object order
● Virtual function call mechanism● Virtual function table format● Use of “thunks”
● Name mangling conventions
● Cannot mix C++ compiler objects● SCO (USLC) C++ ≠ Cfront C++ ≠ GNU g++
16
Features of the OpenServer 6 Dev Sys
● C Compilation System● C++ Compilation System● C/C++ Debugger● memtool● fur
● Except where noted, features apply to Dev Sys used for
both SVR5/UDK and OSR ABIs and to UDK on UW7● A major upgrade compared to existing (and outdated)
OSR5 Development System product!!
17
The OpenServer 6 -K mode switch
● Compilers● /usr/ccs/bin/cc defaults to -Kudk ● /osr5/usr/ccs/bin/cc defaults to -Kosr● “cross-ABI” compiles are allowed
● /usr/ccs/bin/cc -Kosr ...● /osr5/usr/ccs/bin/cc -Kudk …
● ditto CC for C++ compiles – as & ld also● Use cc or CC to do linking – links against correct ABI
startup routines.● Other Dev Sys commands
● have -K osr | udk option if necessary (e.g. lint)● don’t have option if irrelevant (e.g. lex and yacc)
18
OpenServer 6 C Compiler
● Robust compiler, excellent IA-32 code generation
● Standards-conforming libraries and headers
● Profiled versions of libraries● prof, lprof in both ABIs● fprof [SVR5/UDK ABI only]● Standard set of command line
tools, fully internationalized● Conformance checking (-Xc) is
against C 90 standard● Support for Java native methods
[SVR5/UDK ABI only]
● Almost all of C 99 - ISO/IEC 9899:1999● inline, restrict, variable
argument macro functions, & 60 other features
● Only things missing:● variable-length arrays● complex and imaginary
numbers● minor variances in snprintf(3S)
● [some new C99 library functions and headers may be SVR5/UDK ABI only]
● Option –Xb will disable inline and restrict keywords
19
OpenServer 6 C++ Compiler
● Accurate, robust implementation
● Almost all of the C++ standard - ISO/IEC 14882:1998● except rarely-used: export
keyword, placement delete, function-try-blocks, two-phase template name binding, multi-byte characters in source code, partial specialization of a class member template
● Complete C++ Std Library ● STL, iostreams, string, locale,
numerics, etc.● fast and thread-safe
● Excellent IA-32 code generation
● Exception Handling - high ● performance ● Device driver support● Thread safety [SVR5/UDK
ABI only]● Support for Java native
methods [SVR5/UDK ABI only]
20
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Basic - Suggested - Optional
Open Source Tools
21
Basic Open-Source Tools
● Starter set● gmake● autoconf ( 2.13 and 2.59 )● automake - synched with autoconf● GNU m4
● Probably will need (at sometime)● bison● gawk● flex
22
Highly Suggested Open-Source Tools
● Depending on personal preferences, project build or change submission requirements …
● GNU diff● GNU patch● CVS – Concurrent Version System● GNU tar
23
Optional Open-Source Tools
● GNU binutils (gas and ld)● OSR6 assembler
● does not have Willamette SIMD instructions● Minor differences in SIMD mnemonics
● GNU GCC● SIMD instructions are in GCC “asm” statements● Avoid g++ especially for graphics
● C++ ABI issues
● RPM
24
Acquiring Open-Source Tools
● OpenServer 5.0.7 GNU Development Tools● After chsysinfo osr5
● Install GNU m4, bison, flex, diff, patch, awk, make, CVS and configuration creation tools
● DO NOT INSTALL !!!!● GCC – not dual ABI aware
● - Generates OSR5 ABI code● Looks in /usr/include for OSR 5 system headers● Looks in /usr/lib & /usr/ccs/lib for link libraries
● GDB● - Not SVR5 kernel aware
25
Acquiring Open-Source Tools - cont.
● UDK 7.1.4 OSTools set● Install individual packages – not the set chsysinfo uw7 pkgadd -d <mnt-pt> GNUm4 GNUautomk \
GNUautocf GNUmake GNUawk GNUbison \ Osflex
● GCC 2.95.3 and GDB are configured for SVR5
● SVR5 /usr/gnu/lib/libstdc++.so.2.10.0
26
Acquiring Open-Source Tools - cont.
● Additional tools or runtime required to build a project
● Check for availability on Skunkware● May be part of project source
● Part of the normal build sequence● May need to be built as a first step
● May move to the front of your project list● May be optional interface(s)
● Defer / omit now● Build later and rebuild complete project.
27
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Building Open Source Applications
Getting Project Source
28
Getting the Source - From Where ?
● SCO FTP site● ftp://ftp.sco.com/pub/openserver6/600/opensrc● ftp://ftp.sco.com/pub/unixware7/714/opensrc● ftp://ftp.sco.com/pub/openserver5/507/opensrc/source
● SCO Skunkware● http://www.sco.com/skunkware● ftp://ftp2.sco.com/pub/skunkware/src/● ftp://ftp2.sco.com/pub/skunkware/osr6/src/patches/● ftp://ftp2.sco.com/pub/skunkware/uw7/src/patches/
29
Getting the Source - From Where cont.
● Freshmeat web site● http://freshmeat.net
● FileWatcher web site● http://filewatcher.org
● Free Software Foundation FTP● ftp://ftp.gnu.org/gnu
● SUSE Source RPMs FTP site● ftp://ftp.suse.com/pub/suse/i386/update/<version>/rpm/src/
● SourceForge web site ● http://sourceforge.net
30
Source Formats
● Varying Source release formats – choice of project maintainers
● tar or cpio file archives● Often compressed – GNU gzip or
● zip archive files● cvs repository on project hosted site● Linux source RPMs
● Good source for recent patches● Spec file can provide configuration guidance
● Start with patches from the last release
31
Managing Source & Build Changes
● Important to track ALL changes● Avoid reinventing the wheel● Probably need most, if not all, changes in next release● Help others in the SCO community to customize to
their needs● Ultimately to contribute source, build and config.
changes back to the open-source community● Others can reproduce problems and provide solutions
or work-arounds
32
Source Changes - cont:
● Preserve the original source file● Do not over-write previously saved originals
mv [file] [file].orig # preserve orig file date cp [file].orig [file] # modified file – today’s date chmod uw+w [file]
● Create empty “original” for every “new” file
touch [file].orig
33
Source Changes - cont:
● Use context or unified diff to capture changes cd [TOP_OF_SRC_TREE]
for i in `find . –name ‘*.orig’`; do echo $i diff [-c|-u] $i ${i%.orig} done > [project]_cumulative_patch.[date]
● Context or unified diff not applicable to non-text files
● .jar, compressed data, binaries, .jpeg, .pdf, etc.● Copy/replace entirely
34
Source Changes - Build Afresh
● Some open-source projects are configurable for separate source and object directories
● Makefile design/implementation● Blow away the object directory and make again
● Reconstruct project source● Unwind source into “clean” directory
cd [TOP_OF_SRC_TREE] gzcat [ compressed_tar_archive ] | tar -xf -
● Reapply cumulative patches patch -b –p0 < [project]+cumulative_patch.[date] \ 2>&1 | tee log.patch
35
Source Changes - Using Previous Patches
● Prev. release patches may not apply cleanly● Source code changes in area of your patch● Some changes bought-back into project source● Project source restructure
● Unapplied patches written to [file].rej
● Review rejections – rework as needed
find . -name '*.rej'
36
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Building Open Source Applications
Configuration Issues
37
config.guess
● 2001 submitted UW7 changes to FSF to standardize SVR5 triplet
● Handled OpenUNIX 8● i?86:*:5:[78]*
● You may need to update for OSR 6.0.0● i?86:*:5:[678]*
● Produces triplet● i?86-unknown-sysv5<OS name><version>
38
Configure Scripts ? triplet override
● preset HOST / TARGET / BUILD
● SVR5 ABI● i586-sco-sysv5
● OSR5 ABI● i586-sco-sco3.2v5.0.7● add -Kosr to CFLAGS, CXXFLAGS, LDFLAGS
● or set PATH for OSR5 ABI preference
39
Configure Scripts
● Override default use of gcc, if installed● CC=“cc”● CPP=“$CC –E”● CXX=“CC”● RANLIB=true
● Use cc or CC to do the linking● Avoid use of compilation or linking options that
specify default header or library paths● Avoid -I/usr/include –I/usr/include/sys● Avoid -L/usr lib -L/usr/ccs/lib
40
Absence of config.guess
configure and configure.in directly use uname SCO_SV typically configures for OpenServer 5
Correct if using OSR5 ABI Unable to handle LFS files
Resolution – recognize SCO_SV and release 5 as OpenServer 6.0.0 and force selection of SVR5 Hand edit the configure script
or Modify autoconf/aclocal.m4
Rerun autoconf to regenerate an updated configure script
41
scoutils
ftp://ftp2.sco.com/pub/skunkware/osr6/vols/scoutils-1.3Sc-VOLS.cpio ● Shell script frontends
● Configure & build open-source● /usr/bin/Configure, /usr/bin/Build & /usr/bin/Prep
● Project source at:● /usr/src/sco/<category>/<project>-<version>.tar.bz2
● Project patch at:● /usr/src/sco/patches/<project>-<version>-osr6.patch
● cd /usr/src/sco/<category> ● Build <project>
42
scoutils - cont.
● Build ● Extracts source● Applies patch● Run
● <project>-<version>/Configure-OSR6, if it exists ● /usr/bin/Configure, otherwise
● Then run● <project>-<version>/Build-OSR6, if it exists ● GNU make , otherwise
43
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Building Open Source Applications
GCC-isms
44
Need information about gcc extensions?
● Check the gcc information provided in earlier ports
● OSTools – UW 7.1.4● GNUTool Chain – OSR 5.0.7
● /usr/gnu/bin/info gcc
● Select “C extensions”
45
GCC-isms: VarArg Macro Functions
● GCC provided early VarArg Macro Functions #define eprintf(format, args…) fprintf(stderr, format, ##args)
● Supported ISO/IEC 9899 Standard feature #define eprintf(format, …) \ fprintf(stderr, format, __VA_ARGS__)
● Condition the change #ifdef __USLC__ …ISO format #else …GNU format #endif
46
GCC-isms: return <void expression>
● GCC accepts: void bar() { return;}
void foo() { return bar(); }
● To be ISO compliant, change to: void foo() { bar(); return; }
47
GCC-isms: inline C functions
● GCC supported “inline” C functions● Treat function as statement expression at point of call
● ISO/IEC 9899 added “inline” C funtions● Supported on OSR 6.0.0 and UW 7.1.4● Designed to work with C++ “inline” in common headers● Requires 1 and only 1 external definition generated
● If in module source file, probably not an issue● Potential PROBLEM if in a header file
● Suppress “inline” keyword during configuration
CC=“cc –Xb”
48
GCC-isms: statement expressions
● Compound statement in parentheses● Probably encountered in #define #define maxint(a,b) \ ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
● If in a header file, conditionally replace with C static function
static int maxint(a,b) { return (a > b ? a : b); }
49
GCC-isms: __attribute__
● Functions – specify side-effects● Variables – packed, aligned, section, weak● Types – packed, aligned● Format – in declarations or definitions
● __attribute__((<attr_name>[(<arg>)]))● Change needed:
● Conditionally remove attribute modifier● Use, as appropriate:
● #pragma pack(<n>)● #pragma weak <id1> [= <id2>]
50
GCC-isms: Enhanced Asms
● Feature is generally “unique” to each compiler● Used for:
● Better or specialized optimization/performance● Access to hardware registers/instructions not typically
utilized by the C/C++ code generator● With exception to Willamette SIMD instr.
● Recode to SCO Enhanced ASM Function● Prototyped as function Called as a function● Follow i386 calling convention
● Preserve user and stack registers – edi, esi, ebx, ebp, esp● Return values in eax (edx) or fp0
51
GCC-isms: Enhanced Asms - cont.
● OSR 6.0.0 Documentation● Software Development
● Programming in C and C++● Enhanced ASM facility
asm [ type ] identifier ( [ param-list ] ) { [ storage-mode-spec-line asm-body ] + }
storage-mode-spec-line: % [storage-mode [ identifier [, identifier ]* ]; ]
+
52
GCC-isms: Enhanced Asms ? cont.
● Enable optimization of function calling ASM function by:
#pragma partial_optimization <identifier>
● If and only if:● Followed calling and register conventions● Register %ebp has not been modified● Register %esp not modified with movl● No branch into or out of ASM function● auto or param only modified if address of variable is
passed to ASM function● Auto or param accessed if passed by name or address
to ASM function
53
GCC-isms: no equivalents (at present)
● Extended ASMs with Willamette SIMD● Use GCC or separate assembly source compiled with
GNU assembler
● Variable Length Arrays● Local can be recoded using alloca() at function entry● Use GCC
54
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Building Open Source Applications
C++ Issues
55
Template Instantiation
● Different behavior GNU g++ and SCO C++● Can present problems in compilation or linking
● GNU g++
● Instantiates all possibly needed templates in each object file
● Separately named .text sections● GNU collect2/ld eliminates “duplicates” when linking
56
Template Instantiation - cont.
SCO (USLC) – “implicit instantiation”● C++ compiler determines where/when templates are instantiated
● At “link” time● When collected into .so, a.out or .a
● Use CC command to do the linking● Implementation
● Template declaration in xxxx.h● Template definition in xxxx.c – same directory as xxxx.h● Auxiliary files – created by compiler
● source.ti & source.ii (where .o created)- Info to recompile- Templates visible and to be instantiated in that .o
● C++ compiler implicitly includes xxxx.c for needed template in xxxx.h
57
Template Instantiation - cont.
● Non “implicit” source construction● Declaration and definition in header file
● Similarly named .c file visible● Probably related in functionality since same name● Contains non-template class/function definitions
● If .c file is implicitly included in multiple .o● Multiply-defined errors at link time
● Header also contains non-template class/function definitions
● Multiple definitions if headers used by more than single .o● Solution: use preprocessor defines to control visibility
of non-template definitions
58
Template Instantiation - cont.
● C++ templates & archives● Object file is now disassociated from .ti & .ii
● Cannot recompile to get “needed” instantiation● ERROR: - undefined template function later in the build
● “needed” templates must be resolved prior to adding to archive
CC –Tprelink_objects $(OBJS) ar <options> <archive_file> $(OBJS)
59
Friend Name Injection Change
● Slight scoping change in the 1998 C++ Standard● Previously “friend” name was injected in the enclosing
scope● If file scope, became friend to everyone
● Pre-GCC 3.x code may run into this● Most has probably been updated over the last 4 years
61
Truss – trace system calls & signals
● One or many processes● Optionally follow forked process(es)● Optionally indicate LWP id of threaded process
● Asserts control (monitors) process through /proc file system
● Supports both SVR5 and OSR5 ABI processes● Selectively display or suppress:
● System calls● Signals● I/O by file descriptor● Machine faults
● Display system call arguments
62
Truss – command format
truss [-flcaein] [-[tvx] [!] syscall . . .]
[-s [!] signal . . .] [-m [!] fault . . .] [-[rw] [!] fd . . .]
[-o outfile] command | -p pid
● Defaults● -tall● -v!all● -sall● -mall -m!fltpage● -r!all● -w!all
64
OpenServer 6 Debugger - debug
● Graphical user interface● User configurable screen layouts
● Command line interface● powerful, shell-like command language● command history, command aliases
● Strong C and C++ symbolic debugging● Step through inline functions, header code, exceptions
● Controls multi-process, multi-threaded apps● follow forks in both parent and children processes
● Understands ELF/COFF, DWARF I/II executables
65
debug - How to get started
● debug – man page● help command in the debugger
● help – lists available commands and topics● help <cmd-topic> - format and details about
command or topic● Use the on-line/locally installed debugger doc.
“Debugging and analyzing C & C++ Programs”● Command line and GUI
● Tutorials, explanations, and tips
66
debug - Command Format
1. debug [com_opts] [[-p] [-f all|none|procs] [-r] \ [-l start_loc] cmd_line]
2. debug [com_opts] [-f all|none|procs] \ [-l load_file] process...
3. debug [com_opts] [-p] [-m path] -c core_file [object]
debug [com_opts] [-p] [-m path] core_file
com_opts: [-V] [-i c|x] [-X opt] [-d defaults] [-s path] [-Ya,dir]
67
debug - Command Line Interface
● Creating a debug session– create – grab
● Process Execution– run [ -bfr ] [ u location ]– step [ -io ] [ -c count ]– next predefined alias for “step -o”– release– halt
68
debug - Stop Events
● Break points – function, statement, instruction address
● Watch point – value in memory changes● Expression – logical expression is true● Create with:
– stop [-p proc_list] [-c count] stop_expr [command]– Aliased as b
● Manage stop events with:– delete– disable / enable– change– stop
69
debug - Other Events
● Signals – default: monitors every signal– signal -d [ -i ] [ signal,... ] – signal [ -p proclist ] [ -iq ] [ signal, ... [ command ]]
– cancel - removes specified signal(s) from pending signals
– kill - send specified signal(s) ● C++ exceptions
– exception -d [ -i ] { throw | catch }– exception [ -p proclist ] [ -iq ] { throw | catch } [ type ] [ command ]
70
debug - Other Events
● System call tracing– syscall [-p proclist] [[-eqx] [-c count] call ...
[command]]
● On Stop – define action for any stop– onstop [-p proclist] [command]
● Managing all events– events - list event(s) and associate info– enable, disable, delete
71
debug - Displaying Data & Process Information
– stack - display function call back trace– list - list source statements – print - print variables and expressions
● Defaults to “type” of variable● Optional printf() style format string
– dump - hexadecimal/character dump – dis - disassembly of code– regs – general, control, FP & MMX registers– map – list process memory map– whatis – info on variable, function or type– identify – identify a location in memory
72
debug - Personal Configuration
– alias command● define alternate / abbreviated commands● use to establish dbx-like or gdb-like commands● build complex, repetitive, conditional command
sequences● $HOME/.debugrc
● startup debug command script● establish my_former_debugger-like configuration● debug … –d <alt_startup> …
● uses specific alternate startup script instead of default
73
debug - logon / logoff / script
– logon <log_file>● logs debug commands entered and output to a file● generated output appears as comments● capture complete history ● capture repetitive command sequence
– logoff● Terminate logging
– script <file>● reads debug commands from <file>
74
debug - For dbx or gdb users
● dbx users● Section 3 of the Porting Guide “A Guide to debug for
dbx Users”
● gdb users● command comparisons from May/June 2000 SCO
World article● Summary is in the on-line handout
77
memtool - Catching Dynamic Memory Errors
[SVR5/UDK ABI only]● Diagnose dynamic memory allocation errors
● writing beyond a block of memory● using deallocated blocks● memory “leaks”● bad arguments passed to C malloc() or C++ new()
● Does not catch general pointer misuses or writing outside local or global arrays
● Runs the application under the hidden control of the debugger and the dynamic C library malloc runtime checking
78
memtool – Under the covers
diagnostic outputinternal (two-way)
command-line communication
debug
memtool
process control
application process
dynamic C library
basic diagnostic information
user interaction
79
memtool (cont'd)
● Diagnostics include one to three stack traces● when detected● when (de)allocated● previous use (for realloc() or free())
● Erroneously modified block diagnostics include an annotated memory dump snapshot for the block
● Each diagnostic comes with an explanation – short, medium, or long (user selectable)
● Application need not be rebuilt or relinked● debugging (-g flag) provides much better info
80
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Debugging: Dynamic Memory
SVR5 - MALLOC_CHECKS
81
MALLOC_CHECKS - SVR5
● Environment variable activated memory checking in the SVR5 C runtime
● No recompilation needed - dynamic libc.so.1
● MALLOC_CHECKS=<number>● 1 = basic-fill mode● 3 = safe-copy mode - duplicate arena block headers● 5 = added-space mode – allocation padded● mallinfo() - check arena integrity● 2, 4, 6 = above with arena check on all malloc calls
● -1, -5 = high memory edge with electric fence● -3, -7 = low memory edge with electric fence
82
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Debugging: Dynamic Memory
OSR5 - duma / dmalloc
85
fur - FUnction Reorganization
● Instruments and reorders code in relocatable objects - at code block level
● changes function order - locality of reference● reorder code blocks within functions - improves branch prediction● move “low-usage” code to pseudo functions
● Profile guided optimization without recompilation● Actual uses
● Has been used to optimize SCO kernels and libraries● OEMs used fur to gain 15% improvement in Oracle DB
server - TPCC benchmarks● Used for J2SE and soon for Firefox® browser
86
fur – Block profiling [1]
1. Compile and partially link as relocatable object for C++, must prelink before linking: -Tprelink_objects ld -r –o xxxx.rel to link – no runtime libraries save a copy of the xxxx.rel
2. Use fur to instrument every basic block of the xxxx.rel fur –b [all | flow] –K <keep_file> \ -c “mkblocklog –p <log_dir>/block.xxxx” xxxx.rel● instruments xxxx.rel and generates logging code
3. Complete the link producing an instrumented a.out cc/CC … xxxx.rel ….. log.xxxx.o
4. Run representative workloads • multiple runs creates consecutive block.xxxx.??
87
fur – Block profiling [2]
5 Analyze all the log files, creating optimal reordering file copy saved xxxx.rel to xxxx.rel fur –r –o <order_file> -k <keep_file> \ -f <log_dir>/block.xxxx.01,<log_dir>/block.xxxx.02,… -m xxxx.rel
5. Apply the reordering file against the xxxx.rel and complete the FINAL link fur –o <order_file> -k <keep_file> xxxx.rel cc/CC …… xxxx.rel ……
• Once <order_file> is obtained and preserved, only steps #1 and #6 need be done on subsequent rebuilds
• If function shape changes, fur will NOT reorder that function• Heavy source changes – repeat all steps to produce “current”
<order_file>
88
THE SCO GROUP 2007
© The SCO Group, Inc. All Rights Reserved
Packaging
Metapkg and CDMT for OpenServer
89
Creating custom installable packages for OpenServer with Metapkg
● Download and install metapkg fromftp://ftp2.sco.com/pub/skunkware/osr6/metapkg/
● Install metapkg and reman binaries anywhere in root's execution PATH
● Create a symbolic link for mkcdmt (and mkpkgadd if pkgadd installable packages are desired)
ln -s /usr/bin/metapkg /usr/bin/mkcdmt ln -s /usr/bin/metapkg /usr/bin/mkpkgadd
● Documentation in doc subdirectory ftp://ftp2.sco.com/pub/skunkware/osr6/metapkg/doc/
● Examples in examples subdirectory ftp://ftp2.sco.com/pub/skunkware/osr6/metapkg/examples/
90
Preparing the Packaging Hierarchy
● Create input directory and populate dist directory● Create dist/cntl/ scripts, if any● Create <package name>.mkcdmt control file
● Specify non-default permissions and ownership● Symbolic links specified as additional exports● Dependencies and updated versions listed here
● Run mkcdmt. For example: mkcdmt -f -h -d `pwd` -P gimp \ -D "GNU Image Manipulation Program" \ -V 2.2.7Sb -p `pwd`/gimp.mkcdmt
● Run make
91
Sample Metapkg Control File
prepare ("Checking and preparing distribution") {
auto_compress_texinfo();
auto_format_mansource();
auto_strip(TRUE,TRUE);
}
package ("/", "${METAPKG_DESCRIPTION}", "QT3")
{
file ("/usr/lib/qt3/mkspecs/unixware-cc/qmake.conf") {
access (SERVER);
}
file ("/usr/lib/qt3/lib/libqt-mt.so.3.3.8") {
addexport ("/usr/lib/qt3/lib/libqt-mt.so", normal);
}
}
component ("qt3", "${METAPKG_VERSION}", "${METAPKG_DESCRIPTION}")
{
dependency ("SCO:gwxlibs");
upgrades("^3.3.5*");
}
92
Custom Control Scripts (OpenServer)
● Review CDMT documentation at http://osr600doc.sco.com/en/manCDMT/CONTENTS.html
● Use cqs script for pre-installation system prep – for example, creation of new users/groups
● Use ccs script for install/removal config during phases● Adding/removing entries in SCO Help doc system● Setting system specific configuration parameters● Enabling/disabling automatic startup of service(s)● Initializing product configuration (e.g. Setup cache)● Mostly used during PRE_INSTALL, POST_INSTALL,
PRE_REMOVE, and POST_REMOVE phases● If desired, create usr/share/meta/doc/... entries for SCO Help
93
Example CCS Script (Part 1)
#!/bin/sh
scriptname="$0"
step="$1"
keywords="$2"
Pkglist="$3"
. ccsSetup.sh
doPostExport() {
[ -x /usr/bin/doctool ] && {
/usr/bin/doctool --add $DOC/SDK_qt3.desktop
}
}
94
Example CCS Script (Part 2)
doPreUnExport() {
[ -x /usr/bin/doctool ] && {
/usr/bin/doctool –remove $DOC/SDK_qt3.desktop
} } DOC=DevSysDoc/SDKhome/SDKgroup/SDK_qt3
ccs_return_value=0
case "$step" in
POST_EXPORT) doPostExport ;;
PRE_UNEXPORT) doPreUnExport ;;
esac
exit $ccs_return_value
96
Prepare Distribution Hierarchy
● Populate distribution tree● Correct permissions/ownership/group● Set default configuration parameters● Create “admin” and “pkginfo” files at top of tree
PKG="MyProd" NAME="MyProd" VERSION="1.0.1" CATEGORY="application" CLASSES="MyProd" ARCH="i386" BASEDIR=/
97
Prepare Distribution Hierarchy (continued)
● Simple admin file● Basedir=ask
● Create installation scripts if necessary● preinstall/postinstall● preremove/postremove
● Create prototype file● Entries for admin/pkginfo/install scripts
i admin=admin i pkginfo=pkginfo
find <directories> -print | pkgproto >> prototype
98
Create the Package
● Edit prototype file changing any relative symbolic links to absolute symbolic links
● Run pkgmk pkgmk -o -c -d `pwd` -r `pwd`
● Run pkgtrans, if desired, to create a pkgadd datastream
pkgtrans -s `pwd` `pwd`/MyProd.pkg MyProd● Install and test newly created package
pkgadd -d `pwd`/MyProd.pkg all
99
Creating Packages Using Skunkware's mkpkg
● Download and install the mkpkg package ftp://ftp2.sco.com/pub/skunkware/uw7/Packages/mkpkg-1.1.pkg
● Extract distribution tree into empty directory● Set correct permissions/ownership● Run
mkpkg <package name> <package version>● Create installation scripts if necessary● If necessary, edit prototype file and run
./MakePKG● Install and test newly created package
pkgadd -d `pwd`/MyProd.pkg all
101
OpenServer 6 Support Resources
● Porting Guide:● http://www.sco.com/support/docs/openserver/600/
porting/osr6portingTOC.html
● Upgrade Guide:● http://www.sco.com/support/docs/openserver/600/
upgrade/index.html
● Online Documentation and Late News● http://www.sco.com/support/docs/openserver/
102
OpenServer 6 Support Resources
● Support Download Page for OpenServer 6:● http://www.sco.com/support/update/download
/product.php?pfid=12&prid=20
● SCO “Legend” Mailing List: Public● [email protected]● [email protected]
● Porting/Migration Alias:● [email protected]
● Knowledge base:● http://wdb1.sco.com/kb/search