📄 vms.c
字号:
if (vsp->Psect_Index < 255) { PUT_CHAR(TIR$C_STA_PL); PUT_CHAR(vsp->Psect_Index); } else { PUT_CHAR(TIR$C_STA_WPL); PUT_SHORT(vsp->Psect_Index); } PUT_LONG(vsp->Psect_Offset + Offset); break; } /* * Store either a code or data reference */ PUT_CHAR(PC_Relative ? TIR$C_STO_PICR : TIR$C_STO_PIDR); /* * Flush the buffer if it is more than 75% full */ if (Object_Record_Offset > (sizeof(Object_Record_Buffer)*3/4)) Flush_VMS_Object_Record_Buffer();}/* * Check in the text area for an indirect pc-relative reference * and fix it up with addressing mode 0xff [PC indirect] * * THIS SHOULD BE REPLACED BY THE USE OF TIR$C_STO_PIRR IN THE * PIC CODE GENERATING FIXUP ROUTINE. */VMS_Fix_Indirect_Reference(Text_Psect, Offset, fragP, text_frag_root)int Text_Psect;int Offset;register fragS *fragP;struct frag *text_frag_root;{ /* * The addressing mode byte is 1 byte before the address */ Offset--; /* * Is it in THIS frag?? */ if ((Offset < fragP->fr_address) || (Offset >= (fragP->fr_address + fragP->fr_fix))) { /* * We need to search for the fragment containing this * Offset */ for(fragP = text_frag_root; fragP; fragP = fragP->fr_next) { if ((Offset >= fragP->fr_address) && (Offset < (fragP->fr_address + fragP->fr_fix))) break; } /* * If we couldn't find the frag, things are BAD!! */ if (fragP == 0) error("Couldn't find fixup fragment when checking for indirect reference"); } /* * Check for indirect PC relative addressing mode */ if (fragP->fr_literal[Offset - fragP->fr_address] == (char)0xff) { static char Address_Mode = 0xff; /* * Yes: Store the indirect mode back into the image * to fix up the damage done by STO_PICR */ VMS_Set_Psect(Text_Psect,Offset,OBJ$C_TIR); VMS_Store_Immediate_Data(&Address_Mode,1,OBJ$C_TIR); }}/* * Write the Traceback Module Begin record */VMS_TBT_Module_Begin(){ register char *cp,*cp1; int Size; char Module_Name[256]; char Local[256]; /* * Get module name (the FILENAME part of the object file) */ cp = out_file_name; cp1 = Module_Name; while(*cp) { if ((*cp == ']') || (*cp == '>') || (*cp == ':') || (*cp == '/')) { cp1 = Module_Name; cp++; continue; } *cp1++ = islower(*cp) ? toupper(*cp++) : *cp++; } *cp1 = 0; /* * Limit it to 31 characters */ while(--cp1 >= Module_Name) if (*cp1 == '.') *cp1 = 0; if (strlen(Module_Name) > 31) { if(flagseen['+']) printf("%s: Module name truncated: %s\n",myname, Module_Name); Module_Name[31] = 0; } /* * Arrange to store the data locally (leave room for size byte) */ cp = Local+1; /* * Begin module */ *cp++ = DST$C_MODBEG; /* * Unused */ *cp++ = 0; /* * Language type == "C" */ *(long *)cp = DST$C_C; cp += sizeof(long); /* * Store the module name */ *cp++ = strlen(Module_Name); cp1 = Module_Name; while(*cp1) *cp++ = *cp1++; /* * Now we can store the record size */ Size = (cp - Local); Local[0] = Size-1; /* * Put it into the object record */ VMS_Store_Immediate_Data(Local, Size, OBJ$C_TBT);}/* * Write the Traceback Module End record*/VMS_TBT_Module_End(){ char Local[2]; /* * End module */ Local[0] = 1; Local[1] = DST$C_MODEND; /* * Put it into the object record */ VMS_Store_Immediate_Data(Local, 2, OBJ$C_TBT);}/* * Write the Traceback Routine Begin record */VMS_TBT_Routine_Begin(symbolP, Psect)struct symbol *symbolP;int Psect;{ register char *cp,*cp1; char *Name; int Offset; int Size; char Local[512]; /* * Strip the leading "_" from the name */ Name = symbolP->sy_nlist.n_un.n_name; if (*Name == '_') Name++; /* * Get the text psect offset */ Offset = symbolP->sy_nlist.n_value; /* * Calculate the record size */ Size = 1+1+4+1+strlen(Name); /* * Record Size */ Local[0] = Size; /* * Begin Routine */ Local[1] = DST$C_RTNBEG; /* * Uses CallS/CallG */ Local[2] = 0; /* * Store the data so far */ VMS_Store_Immediate_Data(Local, 3, OBJ$C_TBT); /* * Make sure we are still generating a OBJ$C_TBT record */ if (Object_Record_Offset == 0) PUT_CHAR(OBJ$C_TBT); /* * Now get the symbol address */ PUT_CHAR(TIR$C_STA_WPL); PUT_SHORT(Psect); PUT_LONG(Offset); /* * Store the data reference */ PUT_CHAR(TIR$C_STO_PIDR); /* * Store the counted string as data */ cp = Local; cp1 = Name; Size = strlen(cp1) + 1; *cp++ = Size - 1; while(*cp1) *cp++ = *cp1++; VMS_Store_Immediate_Data(Local, Size, OBJ$C_TBT);}/* * Write the Traceback Routine End record * We *must* search the symbol table to find the next routine, since * the assember has a way of reassembling the symbol table OUT OF ORDER * Thus the next routine in the symbol list is not necessarily the * next one in memory. For debugging to work correctly we must know the * size of the routine. */VMS_TBT_Routine_End(Max_Size,sp)int Max_Size;symbolS *sp;{ symbolS *symbolP; int Size = 0x7fffffff; char Local[16]; for(symbolP = symbol_rootP; symbolP; symbolP = symbolP->sy_next) { if ((symbolP->sy_nlist.n_type & ~N_EXT) == N_TEXT) { if (symbolP->sy_nlist.n_un.n_name[0] == 'L') continue; if((symbolP->sy_nlist.n_value > sp->sy_nlist.n_value) && (symbolP->sy_nlist.n_value < Size )) Size = symbolP->sy_nlist.n_value; /* check if gcc_compiled. has size of zero */ if((symbolP->sy_nlist.n_value == sp->sy_nlist.n_value) && sp != symbolP && !strcmp(sp->sy_nlist.n_un.n_name,"gcc_compiled.")) Size = symbolP->sy_nlist.n_value; }; }; if(Size == 0x7fffffff) Size = Max_Size; Size -= sp->sy_nlist.n_value; /* and get the size of the routine */ /* * Record Size */ Local[0] = 6; /* * End of Routine */ Local[1] = DST$C_RTNEND; /* * Unused */ Local[2] = 0; /* * Size of routine */ *((long *)(Local+3)) = Size; /* * Store the record */ VMS_Store_Immediate_Data(Local,7, OBJ$C_TBT);}/* * Write the Traceback Block End record */VMS_TBT_Block_Begin(symbolP, Psect, Name)struct symbol *symbolP;int Psect;char* Name;{ register char *cp,*cp1; int Offset; int Size; char Local[512]; /* * Begin block */ Size = 1+1+4+1+strlen(Name); /* * Record Size */ Local[0] = Size; /* * Begin Block - We simulate with a phony routine */ Local[1] = DST$C_BLKBEG; /* * Uses CallS/CallG */ Local[2] = 0; /* * Store the data so far */ VMS_Store_Immediate_Data(Local, 3, OBJ$C_DBG); /* * Make sure we are still generating a OBJ$C_DBG record */ if (Object_Record_Offset == 0) PUT_CHAR(OBJ$C_DBG); /* * Now get the symbol address */ PUT_CHAR(TIR$C_STA_WPL); PUT_SHORT(Psect); /* * Get the text psect offset */ Offset = symbolP->sy_nlist.n_value; PUT_LONG(Offset); /* * Store the data reference */ PUT_CHAR(TIR$C_STO_PIDR); /* * Store the counted string as data */ cp = Local; cp1 = Name; Size = strlen(cp1) + 1; *cp++ = Size - 1; while(*cp1) *cp++ = *cp1++; VMS_Store_Immediate_Data(Local, Size, OBJ$C_DBG);}/* * Write the Traceback Block End record */VMS_TBT_Block_End(int Size){ char Local[16]; /* * End block - simulate with a phony end routine */ Local[0] = 6; Local[1] = DST$C_BLKEND; *((long *)(Local+3)) = Size; /* * Unused */ Local[2] = 0; VMS_Store_Immediate_Data(Local,7, OBJ$C_DBG);}/* * Write a Line number / PC correlation record */VMS_TBT_Line_PC_Correlation(Line_Number, Offset, Psect, Do_Delta)int Line_Number;int Offset;int Psect;int Do_Delta;{ register char *cp; char Local[64]; /** If not delta, set our PC/Line number correlation*/ if (Do_Delta == 0) { /* * Size */ Local[0] = 1+1+2+1+4; /* * Line Number/PC correlation */ Local[1] = DST$C_LINE_NUM; /* * Set Line number */ Local[2] = DST$C_SET_LINE_NUM; *((unsigned short *)(Local+3)) = Line_Number-1; /* * Set PC */ Local[5] = DST$C_SET_ABS_PC; VMS_Store_Immediate_Data(Local, 6, OBJ$C_TBT); /* * Make sure we are still generating a OBJ$C_TBT record */ if (Object_Record_Offset == 0) PUT_CHAR(OBJ$C_TBT); if (Psect < 255) { PUT_CHAR(TIR$C_STA_PL); PUT_CHAR(Psect); } else { PUT_CHAR(TIR$C_STA_WPL); PUT_SHORT(Psect); } PUT_LONG(Offset); PUT_CHAR(TIR$C_STO_PIDR); /* * Do a PC offset of 0 to register the line number */ Local[0] = 2; Local[1] = DST$C_LINE_NUM; Local[2] = 0; /* Increment PC by 0 and register line # */ VMS_Store_Immediate_Data(Local, 3, OBJ$C_TBT); } else { /* * If Delta is negative, terminate the line numbers */ if (Do_Delta < 0) { Local[0] = 1+1+4; Local[1] = DST$C_LINE_NUM; Local[2] = DST$C_TERM_L; *((long *)(Local+3)) = Offset; VMS_Store_Immediate_Data(Local, 7, OBJ$C_TBT); /* * Done */ return; } /* * Do a PC/Line delta */ cp = Local+1; *cp++ = DST$C_LINE_NUM; if (Line_Number > 1) { /* * We need to increment the line number */ if (Line_Number-1 <= 255) { *cp++ = DST$C_INCR_LINUM; *cp++ = Line_Number-1; } else { *cp++ = DST$C_INCR_LINUM_W; *(short *)cp = Line_Number-1; cp += sizeof(short); } } /* * Increment the PC */ if (Offset <= 128) { *cp++ = -Offset; } else { if (Offset < 0x10000) { *cp++ = DST$C_DELTA_PC_W; *(short *)cp = Offset; cp += sizeof(short); } else { *cp++ = DST$C_DELTA_PC_L; *(long *)cp = Offset; cp += sizeof(long); } } Local[0] = cp - (Local+1); VMS_Store_Immediate_Data(Local,cp - Local, OBJ$C_TBT); }}/* * Describe a source file to the debugger */VMS_TBT_Source_File(Filename, ID_Number)char *Filename;int ID_Number;{ register char *cp,*cp1; int Status,i; char Local[512]; static struct FAB Fab; static struct NAM Nam; static struct XABDAT Date_Xab; static struct XABFHC File_Header_Xab; char Es_String[255],Rs_String[255]; /* * Setup the Fab */ Fab.fab$b_bid = FAB$C_BID; Fab.fab$b_bln = sizeof(Fab); Fab.fab$l_nam = (&Nam); Fab.fab$l_xab = (struct XAB *)&Date_Xab; /* * Setup the Nam block so we can find out the FULL name * of the source file. */ Nam.nam$b_bid = NAM$C_BID; Nam.nam$b_bln = sizeof(Nam); Nam.nam$l_rsa = Rs_String; Nam.nam$b_rss = sizeof(Rs_String); Nam.nam$l_esa = Es_String; Nam.nam$b_ess = sizeof(Es_String); /* * Setup the Date and File Header Xabs */ Date_Xab.xab$b_cod = XAB$C_DAT; Date_Xab.xab$b_bln = sizeof(Date_Xab); Date_Xab.xab$l_nxt = (char *)&File_Header_Xab; File_Header_Xab.xab$b_cod = XAB$C_FHC; File_Header_Xab.xab$b_bln = sizeof(File_Header_Xab);/* ((struct XAB *)&Date_Xab)->xab$b_cod = XAB$C_DAT; *//* ((struct XAB *)&Date_Xab)->xab$b_bln = sizeof(Date_Xab); *//* ((struct XAB *)&Date_Xab)->xab$l_nxt = (struct XAB *)&File_Header_Xab; *//* ((struct XAB *)&File_Header_Xab)->xab$b_cod = XAB$C_FHC; *//* ((struct XAB *)&File_Header_Xab)->xab$b_bln = sizeof(File_Header_Xab); */ /* * Get the file information */ Fab.fab$l_fna = Filename; Fab.fab$b_fns = strlen(Filename); Status = sys$open(&Fab); if (!(Status & 1)) { printf("gas: Couldn't find source file \"%s\", Error = %%X%x\n", Filename, Status); return(0); } sys$close(&Fab); /* * Calculate the size of the resultant string */ i = Nam.nam$b_rsl; /* * Size of record */ Local[0] = 1+1+1+1+1+2+8+4+2+1+1+i+1; /* * Source declaration */ Local[1] = DST$C_SOURCE; /* * Make formfeeds count as source records */ Local[2] = DST$C_SRC_FORMFEED; /* * Declare source file */ Local[3] = DST$C_SRC_DECLFILE; Local[4] = 1+2+8+4+2+1+1+i+1; cp = Local+5; /* * Flags */ *cp++ = 0; /* * File ID */ *(short *)cp = ID_Number; cp += sizeof(short); /* * Creation Date */ *(lo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -