diff -urN bprof/arch.h bprof.new/arch.h --- bprof/arch.h 1970-01-01 01:00:00.000000000 +0100 +++ bprof.new/arch.h 2004-01-12 16:19:40.000000000 +0100 @@ -0,0 +1,19 @@ +/* Machine specific info for Linux using ELF */ + +/* How to get the low and high values of the program counter */ + +extern char _start, _etext; +#define BM_LOWPC (&_start) +#define BM_HIGHPC (&_etext) + +/* How to get the current instruction address */ + +#include +#include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0) +#define BM_SIGARGS int, sigcontext_struct sigcon +#else +#define BM_SIGARGS int, struct sigcontext sigcon +#endif +#define BM_EIP sigcon.eip diff -urN bprof/bmon.cc bprof.new/bmon.cc --- bprof/bmon.cc 1997-04-16 20:12:22.000000000 +0200 +++ bprof.new/bmon.cc 2004-01-12 09:59:52.000000000 +0100 @@ -56,7 +56,7 @@ memset(bbuf, 0, bbufsize * sizeof(*bbuf)); struct sigaction sigact; - sigact.sa_handler = static_cast(profhandler); + sigact.sa_handler = (void (*)(int))(profhandler); sigset_t sigset; sigemptyset(&sigset); sigact.sa_mask = sigset; @@ -85,7 +85,7 @@ // Note that stdio cleanup comes _after_ global destructors. return false; } - address += ret; + address = (char*)address + ret; size -= ret; } return true; diff -urN bprof/bmonout.cc bprof.new/bmonout.cc --- bprof/bmonout.cc 1996-05-08 20:58:14.000000000 +0200 +++ bprof.new/bmonout.cc 2004-01-12 09:59:52.000000000 +0100 @@ -1,12 +1,14 @@ #include #include #include -#include +#include #include // perror() #pragma implementation #include "bmonout.h" +using namespace std; + void bmonout::xread(int fd, void* address, size_t size) { while (size) { @@ -15,7 +17,7 @@ perror("bprof"); exit(1); } - address += ret; + address = ((char*)address + ret); size -= ret; } } diff -urN bprof/bprof.cc bprof.new/bprof.cc --- bprof/bprof.cc 1997-04-16 19:52:17.000000000 +0200 +++ bprof.new/bprof.cc 2004-01-12 16:24:19.000000000 +0100 @@ -4,11 +4,14 @@ #include #include #include +#include #include "bmonout.h" #include "execute.h" #include "sources.h" +using namespace std; + int main(int argc, char* argv[]) { string sffx(".bprof"); // Default suffix @@ -97,7 +100,8 @@ int lastslash = cname.rfind("/"); string dirname = cname.substr(0, lastslash); // Final -1 ??? dir filedir(dirname.c_str()); - int really = gooddirs.count(filedir) ? sourcefile::reallyflag : 0; + // Patch: allow relative dirs + int really = (cname [0] != '/') || gooddirs.count(filedir) ? sourcefile::reallyflag : 0; sourcemap::value_type newkey(cname, new sourcefile(cname, really | verbose)); source.insert(newkey); if (aout.mtime() < source[cname]->mtime()) diff -urN bprof/execute.cc bprof.new/execute.cc --- bprof/execute.cc 1997-04-16 19:39:59.000000000 +0200 +++ bprof.new/execute.cc 2004-01-12 09:59:52.000000000 +0100 @@ -1,8 +1,10 @@ -#include +#include #pragma implementation #include "execute.h" +using namespace std; + // Callback routine to match section names in order to find the text section void executable::findtext(bfd*, asection* sect, PTR thisexec) @@ -33,7 +35,7 @@ } bfd_map_over_sections(thisbfd, findtext, this); - textstart = static_cast(textsec->vma); + textstart = (caddr_t)(textsec->vma); long int symsize = bfd_get_symtab_upper_bound(thisbfd); if (!symsize) { @@ -41,7 +43,7 @@ exit(1); } - syms = static_cast(new char[symsize]); + syms = (typeof(syms))(new char[symsize]); if (!syms) { cerr << "Could not allocate space for symbols!\n"; exit(1); diff -urN bprof/Makefile bprof.new/Makefile --- bprof/Makefile 1997-04-16 20:14:34.000000000 +0200 +++ bprof.new/Makefile 2004-01-12 16:23:31.000000000 +0100 @@ -13,7 +13,7 @@ PROG = bprof BLIB = bmon.o -CXX = gcc +CXX = g++ # Warning flags WFLAGS = -Wall # Debug flags @@ -79,5 +79,3 @@ # I can't stand tar files that unpack in the current directory tar: $(DIST) tar -z -f bprof-$(VERSION).tar.gz -C .. -c $(addprefix bprof/,$^) - -include depend diff -urN bprof/sources.cc bprof.new/sources.cc --- bprof/sources.cc 1995-08-06 17:42:08.000000000 +0200 +++ bprof.new/sources.cc 2004-01-12 16:25:40.000000000 +0100 @@ -1,15 +1,20 @@ -#include +#include +#include #include #include #pragma implementation #include "sources.h" +using namespace std; + sourcefile::sourcefile(string name, int flags) { filename = name; if (!(flags & reallyflag)) { + if(flags & verboseflag) + cout << "Ignoring source file " << name << '\n'; lines = 0; return; } @@ -27,10 +32,19 @@ /* Count the number of lines in the sourcefile. Numlines is actually one larger than this. */ numlines = 1; - char* ch; - while (from.gets(&ch)) { - delete[] ch; - numlines++; + const int line_buffer_size = 100; + char buffer[line_buffer_size]; + while (from.getline(buffer, line_buffer_size, '\n') || from.gcount()) { + if (from.eof()) { + if(flags & verboseflag) + cout << "Partial final line\n"; // from.fail() is false + } else if (from.fail()) { + if(flags & verboseflag) + cout << "Partial long line\n"; + from.clear(from.rdstate() & ~ios::failbit); + } else { + numlines++; + } } lines = new int[numlines]; @@ -81,6 +95,7 @@ // Should check length with pathconf(".", _PC_NAME_MAX) string outname(filename + suffix); unlink(outname.c_str()); // opening with ios::trunc doesn't seem to work ??? + //cout << outname.c_str() << endl; ofstream to(outname.c_str()); if (!to) { cerr << "Could not open " << outname << " to write to\n"; @@ -102,10 +117,16 @@ to.width(6); to << lines[i]; } - char* ch; - from.gets(&ch); - to << '\t' << ch << '\n'; - delete[] ch; + const int line_buffer_size = 1024; + char buffer[line_buffer_size]; + from.getline(buffer, line_buffer_size, '\n'); + to << '\t' << buffer; + while (from.fail()) { + from.clear(from.rdstate() & ~ios::failbit); + from.getline(buffer, line_buffer_size, '\n'); + to << buffer; + } + to << endl; } } diff -urN bprof/sources.h bprof.new/sources.h --- bprof/sources.h 1996-01-05 19:24:37.000000000 +0100 +++ bprof.new/sources.h 2004-01-12 16:27:30.000000000 +0100 @@ -4,9 +4,10 @@ #pragma interface #include +#include class sourcefile { - string filename; + std::string filename; unsigned int numlines; // Number of lines in file + 1 int* lines; // Array of number of ticks int dummy; @@ -17,13 +18,13 @@ sourcefile& operator=(const sourcefile &); sourcefile(const sourcefile &); public: - sourcefile(string, int); + sourcefile(std::string, int); ~sourcefile(); int& operator[](unsigned int); - void paste(string = ".bprof") const; + void paste(std::string = ".bprof") const; time_t mtime() const; - const int reallyflag = 1 << 0; // Use this source file - const int verboseflag = 1 << 1; // Print this source file name + static const int reallyflag = 1 << 0; // Use this source file + static const int verboseflag = 1 << 1; // Print this source file name }; typedef sourcefile* sfpnt; @@ -31,7 +32,7 @@ class dir { dev_t dev; ino_t ino; - const dev_t invalid = 0; // Can dev_t never be 0 ??? + static const dev_t invalid = 0; // Can dev_t never be 0 ??? public: dir(const char*); class less { @@ -39,4 +40,5 @@ bool operator()(const dir&, const dir&) const; }; bool valid() const { return dev != invalid; }; + friend class dir::less; };