|
|
1.1 ! root 1: #include "univ.h" ! 2: #include "process.pri" ! 3: #include "sigmask.h" ! 4: #include "hostcore.h" ! 5: #include "expr.pub" ! 6: #include "master.pub" ! 7: #include "bpts.pri" ! 8: #include "frame.pri" ! 9: #include "memory.pub" ! 10: #include "symtab.pub" ! 11: #include "symbol.h" ! 12: #include "srcdir.h" ! 13: #include "asm.pub" ! 14: #include <CC/stdio.h> ! 15: SRCFILE("hostproc.c") ! 16: ! 17: void HostProcess::takeover() ! 18: { ! 19: trace("%d.takeover()", this); VOK; ! 20: if( pad ){ ! 21: open(); ! 22: insert(ERRORKEY, "take over: already open"); ! 23: return; ! 24: } ! 25: Pick( "take over", (Action)&HostProcess::substitute, (long) this ); ! 26: } ! 27: ! 28: void HostProcess::reopendump() ! 29: { ! 30: char *error; ! 31: ! 32: trace( "%d.reopendump(%d)", this ); VOK; ! 33: insert(ERRORKEY, 0); ! 34: if( error = core->reopen(procpath, stabpath) ){ ! 35: insert(ERRORKEY, error); ! 36: return; ! 37: } ! 38: docycle(); ! 39: } ! 40: ! 41: void HostProcess::substitute(HostProcess *t) ! 42: { ! 43: char *error, *oldprocpath, *oldstabpath, *oldcomment; ! 44: ! 45: trace( "%d.substitute(%d)", this, t ); VOK; ! 46: insert(ERRORKEY, 0); ! 47: if( !core ){ ! 48: insert(ERRORKEY, "that ought to work - but it doesn't"); ! 49: return; ! 50: } ! 51: if( !core->online() ){ ! 52: insert(ERRORKEY, "cannot take over a coredump"); ! 53: return; ! 54: } ! 55: _bpts->lift(); ! 56: if( error = core->reopen(t->procpath, t->stabpath) ){ ! 57: _bpts->lay(); ! 58: insert(ERRORKEY, error); ! 59: return; ! 60: } ! 61: /* t->kill(); */ ! 62: oldprocpath = procpath; ! 63: oldstabpath = stabpath; ! 64: oldcomment = comment; ! 65: procpath = t->procpath; ! 66: stabpath = t->stabpath; ! 67: comment = t->comment; ! 68: master->makeproc( oldprocpath, oldstabpath, oldcomment ); ! 69: master->insert(t); ! 70: master->insert(this); ! 71: banner(); ! 72: if( _asm ) _asm->banner(); ! 73: if( _bpts ) _bpts->banner(); ! 74: if( memory ) memory->banner(); ! 75: if( globals ) globals->banner(); ! 76: if( sigmsk ){ ! 77: sigmsk->banner(); ! 78: sigmsk->updatecore(); ! 79: } ! 80: if( srcdir ) srcdir->banner(); ! 81: core->symtab()->banner(); ! 82: pad->clear(); ! 83: _bpts->lay(); ! 84: docycle(); ! 85: } ! 86: ! 87: int HostProcess::accept( Action a ) ! 88: { ! 89: trace( "%d.accept(%d)", this, a ); OK(0); ! 90: return a == (Action)&HostProcess::substitute; ! 91: } ! 92: ! 93: void HostProcess::imprint() ! 94: { ! 95: trace( "%d.imprint()", this ); VOK; ! 96: char *parentpath = sf("%s%d", slashname(procpath), hostcore()->ppid() ); ! 97: insert(ERRORKEY, "parent=%s", parentpath); ! 98: Process *p = master->search(parentpath); ! 99: if( !p ){ ! 100: insert(ERRORKEY, "parent (%d) not opened", hostcore()->ppid()); ! 101: return; ! 102: } ! 103: _bpts->liftparents(p->_bpts); ! 104: } ! 105: ! 106: void HostProcess::userclose() ! 107: { ! 108: trace( "%d.userclose()", this ); VOK; ! 109: if( sigmsk ){ ! 110: sigmsk->hostclose(); ! 111: delete sigmsk; ! 112: sigmsk = 0; ! 113: } ! 114: Process::userclose(); ! 115: Wait3(); ! 116: } ! 117: ! 118: void HostProcess::open(long ischild) ! 119: { ! 120: Menu m, s; ! 121: char *error; ! 122: ! 123: trace( "%d.open(%d)", this, ischild ); VOK; ! 124: Process::openpad(); ! 125: if( core ) return; ! 126: insert(ERRORKEY, "Checking process and symbol table..."); ! 127: core = (Core*) new HostCore(this, master); ! 128: if( error = core->open() ){ ! 129: delete core; ! 130: core = 0; ! 131: if( ischild ) ! 132: m.last( "open child", (Action)&HostProcess::open, 1 ); ! 133: else ! 134: m.last( "open process", (Action)&HostProcess::open, 0 ); ! 135: pad->menu( m ); ! 136: insert(ERRORKEY, error); ! 137: return; ! 138: } ! 139: insert(ERRORKEY, core->symtab()->warn()); ! 140: globals = new Globals(core); ! 141: _asm = core->newAsm(); ! 142: if( core->online() ){ ! 143: m.last( "stop", (Action)&HostProcess::stop ); ! 144: m.last( "run", (Action)&Process::go ); ! 145: } ! 146: m.last( "src text", (Action)&Process::srcfiles ); /* should check */ ! 147: m.last( "Globals", (Action)&Process::openglobals ); ! 148: m.last( "RawMemory", (Action)&Process::openmemory ); ! 149: s.last( "Assembler", (Action)&Process::openasm ); ! 150: s.last( "User Types",(Action)&Process::opentypes ); ! 151: if( core->online() ){ ! 152: s.last("Journal", (Action)&Process::openjournal); ! 153: s.last("Signals", (Action)&HostProcess::opensigmask); ! 154: s.last("Bpt List", (Action)&HostProcess::openbpts); ! 155: _bpts = new Bpts(core); ! 156: _bpts->lay(); ! 157: if( ischild ) imprint(); ! 158: sigmsk = new SigMask(hostcore()); ! 159: m.last("kill?", (Action)&HostProcess::destroy ); ! 160: } ! 161: m.last(s.index("more")); ! 162: pad->menu(m); ! 163: pad->makecurrent(); ! 164: docycle(); ! 165: } ! 166: ! 167: char *UnixStateName(int s) ! 168: { ! 169: switch( s ){ ! 170: case 0: return "process access error"; ! 171: case SSLEEP: return "sleeping"; ! 172: case SWAIT: return "p_stat=SWAIT"; ! 173: case SRUN: return "running"; ! 174: case SIDL: return "p_stat=SIDL"; ! 175: case SZOMB: return "p_stat=SZOMB"; ! 176: case SSTOP: return "stopped"; ! 177: default: return Name( "p_stat=%d", s ); ! 178: } ! 179: } ! 180: ! 181: void HostProcess::opensigmask() ! 182: { ! 183: trace( "%d.opensigmask()", this ); VOK; ! 184: if( sigmsk ) sigmsk->open(); ! 185: } ! 186: ! 187: void HostProcess::destroy() ! 188: { ! 189: trace( "%d.destroy()", this ); VOK; ! 190: ! 191: IF_LIVE( !core->online() ) return; ! 192: insert(ERRORKEY, core->destroy()); ! 193: docycle(); ! 194: } ! 195: ! 196: void HostProcess::stop() ! 197: { ! 198: trace( "%d.stop()", this ); VOK; ! 199: ! 200: IF_LIVE( !core->online() ) return; ! 201: if( !(sigmsk->mask&sigmsk->bit(SIGSTOP)) ) sigmsk->setsig(SIGSTOP); ! 202: Process::stop(); ! 203: } ! 204: ! 205: Index HostProcess::carte() ! 206: { ! 207: Menu m; ! 208: trace( "%d.carte(%d)", this ); OK(ZIndex); ! 209: if( !strcmp(procpath,"!") ){ ! 210: m.last( "hang & open proc", (Action)&HostProcess::hangopen ); ! 211: m.last( "hang & take over", (Action)&HostProcess::hangtakeover ); ! 212: } else if( !strcmp(basename(procpath), "core") ) ! 213: m.last( "open coredump",(Action)&HostProcess::open ); ! 214: else { ! 215: m.last( "open process", (Action)&HostProcess::open, 0 ); ! 216: m.last( "take over", (Action)&HostProcess::takeover ); ! 217: m.last( "open child", (Action)&HostProcess::open, 1 ); ! 218: } ! 219: return m.index(); ! 220: } ! 221: ! 222: void HostProcess::hang() ! 223: { ! 224: trace( "%d.hang(%s)", this ); VOK; ! 225: int pid = ::fork(); ! 226: if( !pid ){ ! 227: int fd; ! 228: for( fd = 0; fd < _NFILE; ++fd ) ::close(fd); ! 229: ::open("/dev/null", 2); ! 230: ::dup2(0, 1); ! 231: ::dup2(0, 2); ! 232: ::setpgrp(::getpid(), ::getpid()); ! 233: ::execl("/bin/sh","sh","-c",sf("exec hang %s",stabpath),0); ! 234: ::exit(0); ! 235: } ! 236: procpath = sf("/proc/%05d", pid); ! 237: master->makeproc("!", stabpath); ! 238: master->insert(this); ! 239: comment = stabpath; ! 240: stabpath = 0; ! 241: WaitForExecHang(procpath); ! 242: } ! 243: ! 244: void HostProcess::hangopen() ! 245: { ! 246: trace( "%d.hangopen()", this ); VOK; ! 247: hang(); ! 248: open(); ! 249: } ! 250: ! 251: void HostProcess::hangtakeover() ! 252: { ! 253: trace( "%d.hangtakeover()", this ); VOK; ! 254: hang(); ! 255: takeover(); ! 256: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.