wtx.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:300k
- return (WTX_EVTPT_LIST_2 *) &pOut->nEvtpt;
- }
- /*******************************************************************************
- *
- * wtxFileClose - close a file on the target server
- *
- * This routine closes the file previously opened in a call of
- * wtxFileOpen() and cancels any VIO redirection caused by that open.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_CLOSE, wtxFileOpen()
- */
- STATUS wtxFileClose
- (
- HWTX hWtx, /* WTX API handle */
- INT32 fileDescriptor /* file to close descriptor */
- )
- {
- WTX_MSG_RESULT out;
- WTX_MSG_PARAM in;
- WTX_ERROR_T callStat;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
-
- in.param.valueType = V_INT32;
- in.param.value_u.v_int32 = fileDescriptor;
- callStat = exchange (hWtx, WTX_CLOSE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_CLOSE, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxFileOpen - open a file on the target server
- *
- * This routine requests that the target server open a file in the host
- * environment and optionally redirects I/O from a VIO channel to it. The
- * user may select which VIO channel is redirected to and from the file by
- * specifying the <channel> argument.
- *
- * Valid values for the <flags> parameter can be:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_OPEN_FLAG
- *
- * or host specific flags (O_RDONLY etc...) as defined in sys/fcntl.h. The
- * latter are accepted for backward compatibility but should no longer be
- * used.
- *
- * WINDOWS HOSTS
- * If target server runs on a WINDOWS host, the RDONLY flags are not supported.
- * If an RDONLY flag is given for <flags> variable, a WTX_ERR_SVR_INVALID_FLAGS
- * error will be returned. This is due to the lack of pipe opening on WINDOWS
- * hosts.
- *
- * NOTE: <fileName> must specify a file accessible from the host where the
- * target server is running.
- *
- * RETURNS: A file descriptor on success or WTX_ERROR if the open fails.
- *
- * SEE ALSO: WTX_OPEN, wtxFileClose()
- */
- INT32 wtxFileOpen
- (
- HWTX hWtx, /* WTX API handle */
- const char * fileName, /* file name */
- WTX_OPEN_FLAG flags, /* unix style flags */
- INT32 mode, /* unix style mode */
- INT32 channel /* channel id for redirection */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_OPEN_DESC in;
- WTX_MSG_RESULT out;
- INT32 fileId;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (WTX_MSG_OPEN_DESC));
- memset (&out, 0, sizeof (WTX_MSG_RESULT));
- in.filename = (char *) fileName;
- in.flags = flags;
- in.mode = mode;
- in.channel = channel;
- callStat = exchange (hWtx, WTX_OPEN, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- fileId = out.val.value_u.v_int32;
- wtxExchangeFree (hWtx->server, WTX_OPEN, &out);
- return fileId;
- }
- /*******************************************************************************
- *
- * wtxHwBreakpointAdd - create a new WTX eventpoint of type hardware breakpoint
- *
- * This routine creates a new eventpoint on the target to represent a
- * hardware breakpoint of type <type> at the address <tgtAddr> for the
- * target context <contextId>. The target server maintains a list of
- * eventpoints created on the target and this can be queried using
- * wtxEventpointList(). When a context is destroyed on the target or the
- * target is reset, eventpoints are deleted automatically without
- * intervention from the creator.
- *
- * When <contextType> is set to WTX_CONTEXT_SYSTEM, then only eventpoints in
- * system mode can be added.
- * When <contextType> is set to WTX_CONTEXT_TASK, then only eventpoints in
- * context task can be added.
- *
- * The context types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_CONTEXT_TYPE
- *
- * NOTE
- * The types of hardware breakpoints vary with the architectures.
- * Generally, a hardware breakpoint can be a data breakpoint or an
- * instruction breakpoint.
- *
- * RETURNS: The ID of the new breakpoint or WTX_ERROR if the add fails.
- *
- * SEE ALSO: WTX_EVENTPOINT_ADD_2, wtxEventpointAdd(), wtxEventpointDelete(),
- * wtxEventpointList(), wtxBreakpointAdd()
- */
- UINT32 wtxHwBreakpointAdd
- (
- HWTX hWtx, /* WTX API handle */
- WTX_CONTEXT_TYPE contextType, /* type of context to put bp in */
- WTX_CONTEXT_ID_T contextId, /* associated context */
- TGT_ADDR_T tgtAddr, /* breakpoint address */
- TGT_INT_T type /* access type (arch dependant) */
- )
- {
- WTX_MSG_RESULT out;
- WTX_MSG_EVTPT_DESC_2 in;
- WTX_ERROR_T callStat;
- UINT32 hwBpId; /* hardware breakpoint ID */
- TGT_ARG_T args[3];
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- /* fill event field */
- in.wtxEvtpt.event.eventType = WTX_EVENT_HW_BP;
- in.wtxEvtpt.event.args = args;
- in.wtxEvtpt.event.numArgs = (TGT_ARG_T) 3; /* Number of arguments */
- in.wtxEvtpt.event.args[0] = (TGT_ARG_T) tgtAddr; /* bkpt address */
- in.wtxEvtpt.event.args[1] = (TGT_ARG_T) 0; /* bkpt count */
- in.wtxEvtpt.event.args[2] = (TGT_ARG_T) type; /* hw bkpt type */
- /* fill context field */
- in.wtxEvtpt.context.contextType = contextType;
- in.wtxEvtpt.context.contextId = contextId;
- /* fill action field */
- in.wtxEvtpt.action.actionType = WTX_ACTION_STOP|WTX_ACTION_NOTIFY;
- in.wtxEvtpt.action.actionArg = 0;
- in.wtxEvtpt.action.callRtn = 0;
- in.wtxEvtpt.action.callArg = 0;
- callStat = exchange (hWtx, WTX_EVENTPOINT_ADD_2, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- hwBpId = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_EVENTPOINT_ADD_2, &out);
- return hwBpId;
- }
- /*******************************************************************************
- *
- * wtxSymListFree - free memory used to store symbols in a list
- *
- * This routine frees the memory associated with each node in a symbol list.
- *
- * The symbol list to free is defined by:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_LIST
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * RETURNS: N/A
- */
-
- void wtxSymListFree
- (
- WTX_SYM_LIST * pSymList /* symbol list to free */
- )
- {
- WTX_SYMBOL * pCurSym; /* current symbol in list */
- WTX_SYMBOL * pNextSym; /* next symbol in list */
- if (pSymList == NULL)
- return;
-
- pCurSym = pSymList->pSymbol; /* get first node in list */
-
- if(pCurSym == 0) /* list is empty nothing to free */
- return;
-
- pNextSym = (WTX_SYMBOL *) pCurSym->next; /* get next node pointer */
- if (pCurSym->name != NULL)
- {
- free (pCurSym->name); /* free name space */
- }
- if (pCurSym->moduleName != NULL)
- {
- free (pCurSym->moduleName); /* free module name space */
- }
- free (pCurSym); /* free first node space */
-
- while(pNextSym != NULL)
- {
- pCurSym = pNextSym; /* go to next node */
- pNextSym = (WTX_SYMBOL *) pCurSym->next;
-
- if (pCurSym->name != NULL)
- {
- free (pCurSym->name); /* free name space */
- }
- if (pCurSym->moduleName != NULL)
- {
- free (pCurSym->moduleName); /* free module name space */
- }
- free (pCurSym); /* free list node space */
- }
- }
- /*******************************************************************************
- *
- * wtxResultFree - free the memory used by a WTX API call result
- *
- * This routine frees the memory allocated for the result of a WTX API
- * call. <pResult> must point to a WTX structure that was returned by
- * a WTX API call.
- *
- * The routine always returns WTX_OK, except if the WTX handler is invalid. This
- * is to avoid overriding previously set WTX errors.
- *
- * NOTE: To ensure correct and complete freeing of memory allocated to
- * API call results, use wtxResultFree() to free target server call
- * results before calling wtxToolDetach() and to free registry call results
- * before calling wtxTerminate().
- *
- * RETURNS: WTX_OK or WTX_ERROR if the WTX handler is invalid.
- */
- STATUS wtxResultFree
- (
- HWTX hWtx, /* WTX session handler */
- void * pToFree /* pointer to be freed */
- )
- {
- WTX_FREE_NODE * pWtxFreeNode = NULL; /* wtxResultFree node desc */
- WTX_CHECK_HANDLE (hWtx, WTX_ERROR);
- /* first check that the pointer is not NULL */
- if ((pToFree == NULL) || (hWtx->pWtxFreeList == NULL) )
- {
- goto error;
- }
- /* now we can look in the list */
- if ( (pWtxFreeNode = (WTX_FREE_NODE *) sllEach (hWtx->pWtxFreeList,
- wtxPtrMatch, (int) pToFree))
- == NULL)
- {
- goto error;
- }
- /*
- * the pointer pToFree has been found in list, free it by calling the
- * associated routine
- * if pWtxFreeNode->pFreeFunc is set to NULL, it means that we have to
- * free pWtxFreeNode->pToFree using the RPC free routines
- */
- if (pWtxFreeNode->pFreeFunc != NULL)
- {
- pWtxFreeNode->pFreeFunc (pWtxFreeNode->pToFree);
- }
- else
- {
- if (pWtxFreeNode->server != NULL)
- {
- wtxExchangeFree (pWtxFreeNode->server, pWtxFreeNode->svcNum,
- pWtxFreeNode->pMsgToFree);
- }
- }
- /* if the pMsgToFree pointer is not NULL, we have to free it too */
- if ( pWtxFreeNode->pMsgToFree != NULL)
- {
- free (pWtxFreeNode->pMsgToFree);
- }
- sllRemove (hWtx->pWtxFreeList, (SL_NODE *) pWtxFreeNode,
- sllPrevious ( (SL_LIST *) hWtx->pWtxFreeList,
- (SL_NODE *) pWtxFreeNode));
- free (pWtxFreeNode);
- error:
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxFreeAdd - adds an element in the wtxResultFree() list
- *
- * This routine adds a new element in the wtxResultFree() list. It creates a new
- * element in the list. The given <pToFree> and <pFreeFunc> are assigned to the
- * new elemetn <pToFree> and <pFreeFunc> fields.
- *
- * .iP hWtx 10 3
- * The WTX session handler. It allows this routine to return an error message if
- * one request fails.
- * .iP pToFree
- * Basically the pointer that is to be freed by a call to <pFreeFunc>
- * .iP pFreeFunc
- * The address of the routine to use to free <pToFree>
- * .iP pMsgToFree
- * The <pToFree> pointer may be embedded inside a WTX message. In that case, the
- * message also has to be freed. The free() routine is used to free <pMsgToFree>.
- * If <pToFree> is not embedded inside a WTX message, <pMsgToFree> should be set
- * to NULL.
- * .iP svcNum
- * When <pToFree> uses the RPC free routines, this variable should be set to the
- * WTX_REQUEST number of the service that allocated this RPC message. This
- * variable will be evaluated only if the <pFreeFunc> routine pointer is set to
- * NULL.
- * .iP server
- * If <svcNum> is evaluated, the <server> variable specifies the RPC server to
- * connect to.
- * .lE
- *
- * RETURNS: WTX_OK or WTX_ERROR
- *
- */
- STATUS wtxFreeAdd
- (
- HWTX hWtx, /* wtx session handler */
- void * pToFree, /* pointer to be freed */
- FUNCPTR pFreeFunc, /* routine to use to free pToFree */
- void * pMsgToFree, /* message to free if needed */
- WTX_REQUEST svcNum, /* service num to free if needed */
- WTX_XID server, /* RPC server to connect to */
- WTX_SVR_TYPE svrType /* server to connect type */
- )
- {
- WTX_FREE_NODE * pFreeNode = NULL; /* new node in list */
- STATUS status = WTX_ERROR; /* routine return status */
- /* initialize the wtxResultFree list if needed */
- if (hWtx->pWtxFreeList == NULL)
- {
- if ( (hWtx->pWtxFreeList = sllCreate ()) == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- }
- /*
- * add the pointer in the wtxResultFree list so it can be freed later
- * calling wtxResultFree()
- */
- if (pToFree == NULL)
- {
- /*
- * pointer to free is NULL, just don't add it to the list, in order to
- * not break the user's application, we just exit and send the WTX_OK
- * status. There should not be any problem to do it.
- */
- status = WTX_OK;
- goto error;
- }
- /* allocate room for the new pointer description in the queue */
- if ( (pFreeNode = calloc (1, sizeof (WTX_FREE_NODE))) == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- pFreeNode->pToFree = pToFree;
- pFreeNode->pFreeFunc = pFreeFunc;
- pFreeNode->pMsgToFree = pMsgToFree;
- pFreeNode->svcNum = svcNum;
- pFreeNode->server = server ;
- pFreeNode->svrType = svrType;
- sllPutAtTail ( (SL_LIST *) hWtx->pWtxFreeList, (SL_NODE *) pFreeNode);
- status = WTX_OK;
- error:
- return (status);
- }
- /*******************************************************************************
- *
- * wtxPtrMatch - matches with a pointer value
- *
- * This routine is used by wtxResultFree() to match for the pointer to free in
- * the SL_LIST.
- *
- * RETURNS: TRUE if it matches, FALSE if different.
- *
- * NOMANUAL
- */
- LOCAL BOOL wtxPtrMatch
- (
- WTX_FREE_NODE * pWtxFreeNode, /* element in singaly linked list */
- void * pToMatch /* pointer value to find */
- )
- {
- if (pToMatch == pWtxFreeNode->pToFree)
- {
- return (FALSE);
- }
- else
- {
- return (TRUE);
- }
- }
- /*******************************************************************************
- *
- * wtxResultFreeListTerminate - empty the wtxResultFree pointers list
- *
- * This routine is called by wtxTerminate() to free each of the remaining
- * pointers in the wtxResultFree() pointers list.
- *
- * RETURNS: TRUE in order to free all the nodes
- *
- * NOMANUAL
- */
- LOCAL BOOL wtxResultFreeListTerminate
- (
- WTX_FREE_NODE * pWtxFreeNode, /* element in singaly linked list */
- HWTX * hWtx /* WTX session handler */
- )
- {
- wtxResultFree ( (HWTX) (*hWtx), pWtxFreeNode->pToFree);
- return (TRUE);
- }
- /*******************************************************************************
- *
- * wtxResultFreeServerListTerminate - empty the wtxResultFree list for tgtsvr
- *
- * This routine is called by wtxToolDetach() to free each of the remaining
- * target server pointers in the wtxResultFree() pointers list.
- *
- * RETURNS: TRUE in order to free all the nodes
- *
- * NOMANUAL
- */
- LOCAL BOOL wtxResultFreeServerListTerminate
- (
- WTX_FREE_NODE * pWtxFreeNode, /* element in singaly linked list */
- HWTX * hWtx /* WTX session handler */
- )
- {
- if (pWtxFreeNode->svrType == WTX_SVR_SERVER)
- {
- wtxResultFree ( (HWTX) (*hWtx), pWtxFreeNode->pToFree);
- }
- return (TRUE);
- }
- /*******************************************************************************
- *
- * wtxGopherEval - evaluate a Gopher string on the target
- *
- * This routine evaluates the Gopher string <inputString> and populates
- * the Gopher result tape WTX_GOPHER_TAPE with the result
- * data. It is the caller's duty to free the result tape by calling
- * wtxResultFree().
- *
- * EXPAND ../../../include/wtxmsg.h WTX_GOPHER_TAPE
- *
- * The Gopher result tape is a byte-packed (opaque) data stream. The data is a
- * series of pairs, each consisting of a type
- * code and its associated data. The type codes are defined in
- * the file .../wpwr/share/src/agents/wdb/wdb.h as follows:
- *
- * .CS
- * /@ gopher stream format type codes @/
- *
- * #define GOPHER_UINT32 0
- * #define GOPHER_STRING 1
- * #define GOPHER_UINT16 2
- * #define GOPHER_UINT8 3
- * #define GOPHER_FLOAT32 4
- * #define GOPHER_FLOAT64 5
- * #define GOPHER_FLOAT80 6
- * .CE
- *
- * For an example showing how to format the Gopher result tape, see
- * .I API Programmer's Guide: The WTX Protocol.
- *
- * RETURNS: A pointer to the Gopher result tape or NULL on error.
- *
- * SEE ALSO: WTX_GOPHER_EVAL,
- * .I API Reference Manual: WTX Protocol WTX_GOPHER_EVAL,
- * .I API Programmer's Guide: The WTX Protocol
- */
- WTX_GOPHER_TAPE * wtxGopherEval
- (
- HWTX hWtx, /* WTX API handle */
- const char * inputString /* Gopher program to evaluate */
- )
- {
- WTX_MSG_PARAM in;
- WTX_MSG_GOPHER_TAPE * pOut;
- WTX_ERROR_T callStat;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_GOPHER_TAPE));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- memset (&in, 0, sizeof (in));
- in.param.valueType = V_PCHAR;
- in.param.value_u.v_pchar = (char *) inputString;
- callStat = exchange (hWtx, WTX_GOPHER_EVAL, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->tape, NULL, pOut, WTX_GOPHER_EVAL,
- hWtx->server, WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return (&pOut->tape);
- }
- /*******************************************************************************
- *
- * wtxLogging - WDB / WTX requests logging controls
- *
- * This function allows control of WDB / WTX requests logging.
- *
- * Options available for the WTX log request are:
- * .iP LOG_ON
- * Start the logging service
- * .iP LOG_OFF
- * Stop the logging service
- * .iP filename
- * Name where info will be written
- * .iP maxSize
- * Maximum size of the log file
- * .iP regExp
- * Regular expression used to filter events
- *
- * Options available for the WDB log request are:
- * .iP LOG_ON
- * Start the logging service
- * .iP LOG_OFF
- * Stop the logging service
- * .iP filename
- * Name where info will be written
- * .iP maxSize
- * Maximum size of the log file
- *
- * By default, there's no maximum size (<maxSize> is set to WTX_LOG_NO_LIMIT)
- * and <regExp> is set to "WTX_EVENT_GET".
- *
- * EXAMPLE:
- *
- * Start the WTX logging with a file never bigger than 10000 bytes and
- * containing all WTX requests except "WTX_TOOL_ATTACH".
- *
- * .CS
- * wtxLogging (
- * hWtx, /@ WTX API handle @/
- * LOG_WTX, /@ WTX logging @/
- * LOG_ON, /@ start logging @/
- * "/folk/pascal/wtx.txt", /@ log file name @/
- * 10000, /@ log max size @/
- * "WTX_TOOL_ATTACH" /@ never printed @/
- * );
- * .CE
- *
- * Start the WTX logging without size limit and with a default WTX
- * requests filter.
- *
- * .CS
- * wtxLogging (
- * hWtx, /@ WTX API handle @/
- * LOG_WTX, /@ WTX logging @/
- * LOG_ON, /@ start logging @/
- * "/folk/pascal/wtx.txt", /@ log file name @/
- * WTX_LOG_NO_LIMIT, /@ no max size @/
- * NULL /@ default filter @/
- * );
- * .CE
- *
- * Stop the WTX and the WDB logging in one call: <fileName>, <maxSize> and
- * <filter> are not used in this case and may be set to a default value.
- *
- * .CS
- * wtxLogging (
- * hWtx, /@ WTX API handle @/
- * LOG_ALL, /@ WTX WDB log @/
- * LOG_OFF, /@ stop logging @/
- * NULL, /@ not used @/
- * WTX_LOG_NO_LIMIT, /@ not used @/
- * NULL /@ not used @/
- * );
- * .CE
- *
- * RETURNS: WTX_OK or WTX_ERROR
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <fileName> is NULL or an argument is wrong
- *
- * SEE ALSO: WTX_COMMAND_SEND,
- */
- STATUS wtxLogging
- (
- HWTX hWtx, /* WTX API handle */
- int type, /* LOG_WDB, LOG_WTX or LOG_ALL logging */
- int action, /* Logging LOG_ON or LOG_OFF */
- char * fileName, /* Logging file name */
- int maxSize, /* log file max size */
- char * filter /* Filter for the log file. */
- )
- {
- WTX_MSG_RESULT out;
- WTX_MSG_PARAM in;
- char commandString [256];
- WTX_ERROR_T callStat;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- /* Is it a WTX_LOGGING request ? */
- if (type == LOG_WTX)
- {
- /* We want to activate the logging facilities */
- if (action == LOG_ON)
- {
- /* Test the arguments */
- if (fileName == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if (maxSize < 0)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if (filter == NULL)
- {
- /* We have the max size */
- sprintf (commandString, "%s%s%s%s%d", WTX_LOGGING_ON_CMD,
- SEPARATOR, fileName, SEPARATOR, maxSize);
- }
- else
- {
- /* We have a filter for the log file */
- sprintf (commandString, "%s%s%s%s%d%s%s", WTX_LOGGING_ON_CMD,
- SEPARATOR, fileName, SEPARATOR, maxSize, SEPARATOR,
- filter);
- }
- }
- else
- {
- /* We want to stop the logging facilities */
- if (action == LOG_OFF)
- {
- sprintf (commandString, "%s", WTX_LOGGING_OFF_CMD);
- }
- /* This is an error */
- else
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- }
- }
- }
- else
- {
- /* Is it a WDB_LOGGING request ? */
- if (type == LOG_WDB)
- {
- /* We want to activate the logging facilities */
- if (action == LOG_ON)
- {
- /* Test the arguments */
- if (fileName == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if (maxSize < 0)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- /* We have the max size */
- sprintf (commandString, "%s%s%s%s%d", WDB_LOGGING_ON_CMD,
- SEPARATOR, fileName, SEPARATOR, maxSize);
- }
- else
- {
- /* We want to stop the logging facilities */
- if (action == LOG_OFF)
- {
- sprintf (commandString, "%s", WDB_LOGGING_OFF_CMD);
- }
- /* This is an error */
- else
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- }
- }
- }
- else
- {
- /* Is it a WTX_LOGGING & WDB_LOGGING <LOG_OFF> request ? */
- if (type == LOG_ALL)
- {
- /* If this is <LOG_OFF>: OK */
- if (action == LOG_OFF)
- {
- sprintf (commandString, "%s", ALL_LOGGING_OFF_CMD);
- }
- else
- {
- /* This is an error */
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- }
- }
- else
- {
- /* Otherwise: error */
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- }
- }
- }
- in.param.valueType = V_PCHAR;
- in.param.value_u.v_pchar = commandString;
- callStat = exchange (hWtx, WTX_COMMAND_SEND, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_COMMAND_SEND, &out);
- /* Tchao */
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxMemInfoGet - get information about the target-server-managed memory pool
- *
- * This routine queries the target server to find out information about
- * the target-server-managed target memory pool. The result is a pointer
- * to a WTX_MEM_INFO structure that must be freed by a user call to
- * wtxResultFree().
- *
- * EXPAND ../../../include/wtx.h WTX_MEM_INFO
- *
- * RETURNS: Pointer to the module info or NULL on failure.
- *
- * SEE ALSO: WTX_MEM_INFO_GET, wtxMemAlloc().
- */
- WTX_MEM_INFO * wtxMemInfoGet
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat; /* WTX status */
- WTX_MSG_MEM_INFO * pOut;
- WTX_CHECK_CONNECTED (hWtx, NULL);
-
- pOut = calloc (1, sizeof (WTX_MSG_MEM_INFO));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_MEM_INFO_GET, &hWtx->msgToolId, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->curBytesFree, NULL, pOut,
- WTX_MEM_INFO_GET, hWtx->server, WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_MEM_INFO *) &pOut->curBytesFree);
- }
- /*******************************************************************************
- *
- * wtxMemAlloc - allocate a block of memory to the TS-managed target memory pool
- *
- * This routine allocates <numBytes> of memory on the target. The block
- * location and alignment are unspecified.
- *
- * RETURNS: The address of the target memory allocated or NULL on error.
- *
- * SEE ALSO: WTX_MEM_ALLOC, wtxMemFree()
- */
- TGT_ADDR_T wtxMemAlloc
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 numBytes /* size to allocate in bytes */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_PARAM in;
- WTX_MSG_RESULT out;
- TGT_ADDR_T result;
- WTX_CHECK_CONNECTED (hWtx, 0);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.param.valueType = V_UINT32;
- in.param.value_u.v_uint32 = numBytes;
- callStat = exchange (hWtx, WTX_MEM_ALLOC, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, 0);
- result = out.val.value_u.v_tgt_addr;
- wtxExchangeFree (hWtx->server, WTX_MEM_ALLOC, &out);
- return result;
- }
- /*******************************************************************************
- *
- * wtxMemChecksum - perform a checksum on target memory
- *
- * This routine returns a checksum for <numBytes> of memory starting at
- * address <startAddr>. Errors must be detected by using the wtxErrXXX()
- * routines.
- *
- * RETURNS: A checksum value.
- *
- * SEE ALSO: WTX_MEM_CHECKSUM
- */
- UINT32 wtxMemChecksum
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T startAddr, /* remote addr to start checksum at */
- UINT32 numBytes /* number of bytes to checksum */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_SET_DESC in;
- WTX_MSG_RESULT out;
- UINT32 result;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = startAddr;
- in.numItems = numBytes;
- callStat = exchange (hWtx, WTX_MEM_CHECKSUM, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- result = out.val.value_u.v_uint32;
- wtxExchangeFree (hWtx->server, WTX_MEM_CHECKSUM, &out);
- return result;
- }
- /*******************************************************************************
- *
- * wtxMemMove - move a block of target memory
- *
- * This routine moves <numBytes> from <srcAddr> to <destAddr>. Note that
- * the source and destination buffers may overlap.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_MOVE
- */
- STATUS wtxMemMove
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T srcAddr, /* remote addr to move from */
- TGT_ADDR_T destAddr, /* remote addr to move to */
- UINT32 numBytes /* number of bytes to move */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_MOVE_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.source = srcAddr;
- in.destination = destAddr;
- in.numBytes = numBytes;
- callStat = exchange (hWtx, WTX_MEM_MOVE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_MOVE, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxMemFree - free a block of target memory
- *
- * This routine frees a target memory block previously allocated with
- * wtxMemAlloc().
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_FREE, wtxMemAlloc()
- */
- STATUS wtxMemFree
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T address /* target memory block address to free */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_PARAM in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.param.valueType = V_TGT_ADDR;
- in.param.value_u.v_tgt_addr = address;
- callStat = exchange (hWtx, WTX_MEM_FREE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_FREE, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxMemRead - read memory from the target
- *
- * This routine reads <numBytes> of memory from the target starting at
- * <fromAddr> and writes the contents to <toAddr>.
- *
- * NOTE: Because the target agent tests that all memory is readable,
- * this routine can never do a partial read. The return value is
- * always <numBytes> or WTX_ERROR.
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <toAddr> or <numBytes> is invalid.
- *
- * RETURNS: The number of bytes read (see note) or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_READ, wtxMemWrite()
- */
- UINT32 wtxMemRead
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T fromAddr, /* Target addr to read from */
- void * toAddr, /* Local addr to read to */
- UINT32 numBytes /* Bytes to read */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_READ_DESC in;
- WTX_MSG_MEM_COPY_DESC out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if ((toAddr == 0) || (numBytes == 0))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.source = fromAddr;
- in.destination = (UINT32) toAddr;
- in.numBytes = numBytes;
- callStat = exchange (hWtx, WTX_MEM_READ, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_READ, &out);
- /* NOTE : WTX_MEM_READ can only read 0 or all of the bytes, hence the
- * return value is actually 0 (a status code == WTX_OK) when all is
- * well.
- */
- return numBytes;
- }
- /*******************************************************************************
- *
- * wtxMemWidthRead - read memory from the target
- *
- * This routine reads <numBytes> (on <width> bytes large) from the target
- * starting at <fromAddr> and writes the contents to <toAddr>.
- *
- * NOTE: Because the target agent tests that all memory is readable,
- * this routine can never do a partial read. The return value is
- * always <numBytes> or WTX_ERROR.
- *
- * NOTE: This request is not implemented on WDB side, wtxMemWidthRead()
- * is mapped on wtxMemRead() and the <width> parameter is simply ignored.
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <toAddr>, <numBytes> or <width> is invalid
- *
- * RETURNS: The number of bytes read (see note) or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_WIDTH_READ, wtxMemRead(), wtxMemWidthWrite()
- */
- UINT32 wtxMemWidthRead
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T fromAddr, /* Target addr to read from */
- void * toAddr, /* Local addr to read to */
- UINT32 numBytes, /* Bytes to read */
- UINT8 width /* Value width in bytes */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_WIDTH_READ_DESC in;
- WTX_MSG_MEM_COPY_DESC out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if ((toAddr == 0) || (numBytes == 0))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if ((width != 1) && (width != 2) && (width != 4))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.source = fromAddr;
- in.destination = (UINT32) toAddr;
- in.numBytes = numBytes;
- in.width = width;
- callStat = exchange (hWtx, WTX_MEM_WIDTH_READ, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_WIDTH_READ, &out);
- /*
- * NOTE : WTX_MEM_WIDTH_READ can only read 0 or all of the bytes, hence the
- * return value is actually 0 (a status code == WTX_OK) when all is
- * well.
- */
- return (numBytes);
- }
- /*******************************************************************************
- *
- * wtxMemWrite - write memory on the target
- *
- * This routine writes <numBytes> of memory to <toAddr> on the target from
- * the local address <fromAddr>.
- *
- * NOTE: Because the target agent tests that all memory is writable,
- * this routine can never do a partial write. The return value is
- * always <numBytes> or WTX_ERROR.
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <fromAddr> or <numBytes> is invalid.
- *
- * RETURNS: The number of bytes written (see note) or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_WRITE, wtxMemRead()
- */
- UINT32 wtxMemWrite
- (
- HWTX hWtx, /* WTX API handle */
- void * fromAddr, /* Local addr to write from */
- TGT_ADDR_T toAddr, /* Remote addr to write to */
- UINT32 numBytes /* Bytes to read */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_COPY_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if ((fromAddr == 0) || (numBytes == 0))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.source = (UINT32) fromAddr;
- in.destination = toAddr;
- in.numBytes = numBytes;
- callStat = exchange (hWtx, WTX_MEM_WRITE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_WRITE, &out);
- /* NOTE : WTX_MEM_WRITE can only write 0 or all of the bytes, hence the
- * return value is actually 0 (a status code == WTX_OK) when all is
- * well.
- */
- return numBytes;
- }
- /*******************************************************************************
- *
- * wtxMemWidthWrite - write memory on the target
- *
- * This routine writes <numBytes> (on <width> bytes large) at <toAddr>
- * on the target from the local address <fromAddr>.
- *
- * NOTE: Because the target agent tests that all memory is writable,
- * this routine can never do a partial write. The return value is
- * always <numBytes> or WTX_ERROR.
- *
- * NOTE: This request is not implemented on WDB side,
- * wtxMemWidthWrite() is mapped on wtxMemWrite() and the <width> parameter is
- * simply ignored.
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <fromAddr>, <numBytes> or <width> is invalid
- *
- * RETURNS: The number of bytes written (see note) or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_WIDTH_WRITE, wtxMemWrite(), wtxMemWidthRead()
- */
- UINT32 wtxMemWidthWrite
- (
- HWTX hWtx, /* WTX API handle */
- void * fromAddr, /* Local addr to write from */
- TGT_ADDR_T toAddr, /* Remote addr to write to */
- UINT32 numBytes, /* Bytes to read */
- UINT8 width /* Width value: 1, 2, 4 bytes */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_WIDTH_COPY_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- if ((fromAddr == 0) || (numBytes == 0))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- if ((width != 1) && (width != 2) && (width != 4))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- in.source = (UINT32) fromAddr;
- in.destination = toAddr;
- in.numBytes = numBytes;
- in.width = width;
- callStat = exchange (hWtx, WTX_MEM_WIDTH_WRITE, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_WIDTH_WRITE, &out);
- /*
- * NOTE : WTX_MEM_WIDTH_WRITE can only write 0 or all of the bytes, hence
- * the return value is actually 0 (a status code == WTX_OK) when all is
- * well.
- */
- return (numBytes);
- }
- /*******************************************************************************
- *
- * wtxMemSet - set target memory to a given value
- *
- * This routine sets <numBytes> at address <addr> to the value <val>.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_SET
- */
- UINT32 wtxMemSet
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T addr, /* remote addr to write to */
- UINT32 numBytes, /* number of bytes to set */
- UINT32 val /* value to set */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_SET_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = addr;
- in.width = 1;
- in.numItems = numBytes;
- in.value = (UINT32) val;
- callStat = exchange (hWtx, WTX_MEM_SET, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_SET, &out);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxMemAddToPool - add memory to the agent pool
- *
- * This function adds the block of memory starting at <address> and spanning
- * <size> bytes to the agent pool, enlarging it. It is possible to enlarge
- * the agent pool with memory obtained from the runtime memory manager
- * or with any currently unclaimed memory.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_ADD_TO_POOL, wtxMemInfoGet(), wtxMemAlloc(),
- * wtxMemRealloc(), wtxMemFree()
- */
- STATUS wtxMemAddToPool
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T address, /* base of memory block to add */
- UINT32 size /* size of memory block to add */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_BLOCK_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = address;
- in.numBytes = size;
- callStat = exchange (hWtx, WTX_MEM_ADD_TO_POOL, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_MEM_ADD_TO_POOL, &out);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxMemRealloc - reallocate a block of target memory
- *
- * This function changes the size of the block starting at <address> to
- * <numBytes> bytes and returns the address of the block (which may have moved).
- *
- * RETURNS: The address of the target memory reallocated or NULL on error.
- *
- * SEE ALSO: WTX_MEM_REALLOC, wtxMemAlloc()
- */
- TGT_ADDR_T wtxMemRealloc
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T address, /* memory block to reallocate */
- UINT32 numBytes /* new size */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_BLOCK_DESC in;
- WTX_MSG_RESULT out;
- TGT_ADDR_T result;
- WTX_CHECK_CONNECTED (hWtx, 0);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = address;
- in.numBytes = numBytes;
- callStat = exchange (hWtx, WTX_MEM_REALLOC, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, 0);
- result = out.val.value_u.v_tgt_addr;
- wtxExchangeFree (hWtx->server, WTX_MEM_REALLOC, &out);
- return result;
- }
- /******************************************************************************
- *
- * wtxMemAlign - allocate aligned target memory
- *
- * This function allocates a block of memory of <numBytes> bytes aligned on
- * a <alignment>-byte boundary. <alignment> must be a power of 2.
- *
- * RETURNS: The address of the target memory allocated or NULL on error.
- *
- * SEE ALSO: WTX_MEM_ALIGN, wtxMemAlloc()
- */
- TGT_ADDR_T wtxMemAlign
- (
- HWTX hWtx, /* WTX API handle */
- TGT_ADDR_T alignment, /* alignment boundary */
- UINT32 numBytes /* size of block to allocate */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_BLOCK_DESC in;
- WTX_MSG_RESULT out;
- TGT_ADDR_T result;
- WTX_CHECK_CONNECTED (hWtx, 0);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = alignment;
- in.numBytes = numBytes;
- callStat = exchange (hWtx, WTX_MEM_ALIGN, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, 0);
- result = out.val.value_u.v_tgt_addr;
- wtxExchangeFree (hWtx->server, WTX_MEM_ALIGN, &out);
- return result;
- }
- /******************************************************************************
- *
- * wtxMemScan - scan target memory for the presence or absence of a pattern
- *
- * This routine scans the target memory from <startAddr> to <endAddr>.
- * When <match> is set to TRUE, the first address containing the pattern
- * pointed to by <pattern> is returned. When <match> is
- * FALSE, the first address not matching <pattern> is returned.
- * <pattern> is a pointer to a host array of byte values of length
- * <numBytes>. If the pattern cannot be found then an error is returned.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_MEM_SCAN
- */
- STATUS wtxMemScan
- (
- HWTX hWtx, /* WTX API handle */
- BOOL32 match, /* Match/Not-match pattern boolean */
- TGT_ADDR_T startAddr, /* Target address to start scan */
- TGT_ADDR_T endAddr, /* Target address to finish scan */
- UINT32 numBytes, /* Number of bytes in pattern */
- void * pattern, /* Pointer to pattern to search for */
- TGT_ADDR_T * pResult /* Pointer to result address */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MEM_SCAN_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- if (pResult == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.startAddr = startAddr;
- in.endAddr = endAddr;
- in.numBytes = numBytes;
- in.pattern = pattern;
- in.match = match ;
- callStat = exchange (hWtx, WTX_MEM_SCAN, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- *pResult = out.val.value_u.v_tgt_addr;
- wtxExchangeFree (hWtx->server, WTX_MEM_SCAN, &out);
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxObjModuleChecksum - checks validity of target memory.
- *
- * This routine compares object module checksum on target with object module
- * checksum in target server memory cache. This is a way to control the
- * target memory integrity. If <moduleId> is set to WTX_ALL_MODULE_ID or
- * <fileName> set to "WTX_ALL_MODULE_CHECK" then all modules will be checked.
- *
- * NOTE:
- * Because elf modules may have more than 1 section of text, text sections
- * are gathered in a text segment. But, if on the target memory (or in the
- * module) sections are contigous, they may not be contigous in the host
- * memory cache (due to different malloc for each sections). Then checksums
- * cannot be compared for the text segment but only for the first text section.
- *
- * ERRORS:
- * .iP WTX_ERR_API_MEMALLOC 12
- * <fileName> buffer cannot be allocated
- * .iP WTX_ERR_API_INVALID_ARG
- * <moduleId> or <fileName> invalid
- *
- * RETURN: WTX_OK or WTX_ERROR if exchange failed
- *
- * SEE ALSO: WTX_OBJ_MODULE_CHECKSUM, wtxObjModuleList(), wtxMemChecksum()
- */
- STATUS wtxObjModuleChecksum
- (
- HWTX hWtx, /* WTX API handle */
- INT32 moduleId, /* Module Id */
- char * fileName /* Module name */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- if ((moduleId == 0) || (moduleId == WTX_ERROR) || (fileName == NULL))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
-
- in.moduleId = moduleId;
- in.filename = fileName;
- if (moduleId == WTX_ALL_MODULE_ID)
- {
- if ((in.filename = (char *) malloc (strlen (WTX_ALL_MODULE_CHECK) + 1))
- == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, WTX_ERROR);
- strcpy (in.filename, WTX_ALL_MODULE_CHECK);
- }
- callStat = exchange (hWtx, WTX_OBJ_MODULE_CHECKSUM, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_MODULE_CHECKSUM, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxObjModuleFindId - find the ID of an object module given its name
- *
- * This routine returns the ID of the object module that was loaded
- * from the file with the name <moduleName>. The object name must not
- * include any directory components as this is not stored in the
- * object module.
- *
- * RETURNS: The object module ID or WTX_ERROR.
- *
- * SEE ALSO: WTX_OBJ_MODULE_FIND, wtxObjModuleFindName(), wtxObjModuleInfoGet()
- */
- UINT32 wtxObjModuleFindId
- (
- HWTX hWtx, /* WTX API handle */
- const char * moduleName /* object module file name */
- )
- {
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_MOD_NAME_OR_ID out;
- WTX_ERROR_T callStat;
- UINT32 moduleId;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.filename = (char *) moduleName;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_FIND, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- moduleId = out.moduleId;
- wtxExchangeFree (hWtx->server, WTX_OBJ_MODULE_FIND, &out);
- return out.moduleId;
- }
- /*******************************************************************************
- *
- * wtxObjModuleFindName - find object module name given its ID
- *
- * This routine returns the name of the object for the module that has
- * the ID <moduleId>. The name returned is the name of the object file
- * from which it was loaded and does not include the directory where
- * the object file was loaded. The returned string must be freed by
- * the user calling wtxResultFree().
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <moduleId> is invalid
- *
- * RETURNS: The object module filename or NULL.
- *
- * SEE ALSO: WTX_OBJ_MODULE_FIND, wtxObjModuleFindId(), wtxObjModuleInfoGet()
- */
- char * wtxObjModuleFindName
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 moduleId /* id of module to find object name of */
- )
- {
- WTX_MSG_MOD_NAME_OR_ID * pOut = NULL;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_ERROR_T callStat;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- memset (&in, 0, sizeof (in));
- if ((moduleId == 0) || (moduleId == (UINT32) WTX_ERROR))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- /* arguments have been checked, allocate room for the out structure */
- pOut = (WTX_MSG_MOD_NAME_OR_ID *) calloc (1,
- sizeof (WTX_MSG_MOD_NAME_OR_ID));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- in.moduleId = moduleId;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_FIND, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) pOut->filename, NULL, pOut,
- WTX_OBJ_MODULE_FIND, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return (pOut->filename);
- }
- /*******************************************************************************
- *
- * wtxObjModuleInfoGet - return information on a module given its module ID
- *
- * This routine returns a pointer to a module information structure for
- * the module with the supplied ID <modId>. The module information must be
- * freed by the user calling wtxResultFree().
- *
- * EXPAND ../../../include/wtx.h WTX_MODULE_INFO
- *
- * where OBJ_SEGMENT is:
- *
- * EXPAND ../../../include/wtxmsg.h OBJ_SEGMENT
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <modId> is invalid
- *
- * RETURNS: A pointer to the module information structure or NULL on error.
- *
- * SEE ALSO: WTX_OBJ_MODULE_INFO_GET, wtxObjModuleList()
- */
- WTX_MODULE_INFO * wtxObjModuleInfoGet
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 modId /* id of module to look for */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_MODULE_INFO * pOut;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if ((modId == 0) || (modId == (UINT32) WTX_ERROR))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- memset (&in, 0, sizeof (in));
- in.moduleId = modId;
- in.filename = NULL;
- pOut = calloc (1, sizeof (WTX_MSG_MODULE_INFO));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_OBJ_MODULE_INFO_GET, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->moduleId, NULL, pOut,
- WTX_OBJ_MODULE_INFO_GET, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_MODULE_INFO *) &pOut->moduleId);
- }
- /*******************************************************************************
- *
- * wtxObjModuleInfoAndPathGet - return information on a module given its ID
- *
- * This routine returns a pointer to a module information structure for
- * the module with the supplied ID <modId>. The module information must be
- * freed by the user calling wtxResultFree().
- *
- * This request returned the complete pathname in the <name> field of the
- * result.
- *
- * EXPAND ../../../include/wtx.h WTX_MODULE_INFO
- *
- * where OBJ_SEGMENT is:
- *
- * EXPAND ../../../include/wtxmsg.h OBJ_SEGMENT
- *
- * ERRORS:
- * .iP WTX_ERR_API_INVALID_ARG 12
- * <modId> is invalid
- *
- * RETURNS: A pointer to the module information structure or NULL on error.
- *
- * SEE ALSO: WTX_OBJ_MODULE_INFO_GET, wtxObjModuleInfoGet(), wtxObjModuleList()
- */
- WTX_MODULE_INFO * wtxObjModuleInfoAndPathGet
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 modId /* id of module to look for */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_MODULE_INFO * pOut;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- if ((modId == 0) || (modId == (UINT32) WTX_ERROR))
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- memset (&in, 0, sizeof (in));
- in.moduleId = modId;
- in.filename = WTX_OBJ_MODULE_PATHNAME_GET;
- pOut = calloc (1, sizeof (WTX_MSG_MODULE_INFO));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_OBJ_MODULE_INFO_GET, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->moduleId, NULL, pOut,
- WTX_OBJ_MODULE_INFO_GET, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_MODULE_INFO *) &pOut->moduleId);
- }
- /*******************************************************************************
- *
- * wtxObjModuleList - fetch a list of loaded object modules from the target
- *
- * This routine queries the target server symbol table for a list of
- * loaded modules. A pointer to the module list is returned and must
- * be freed by the caller using wtxResultFree().
- *
- * EXPAND ../../../include/wtx.h WTX_MODULE_LIST
- *
- * RETURNS: A pointer to the module list or NULL on error.
- *
- * SEE ALSO: WTX_OBJ_MODULE_LIST, wtxObjModuleInfoGet()
- */
- WTX_MODULE_LIST * wtxObjModuleList
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MODULE_LIST * pOut;
- WTX_CHECK_CONNECTED (hWtx, NULL);
- pOut = calloc (1, sizeof (WTX_MSG_MODULE_LIST));
- if (pOut == NULL)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- callStat = exchange (hWtx, WTX_OBJ_MODULE_LIST, &hWtx->msgToolId, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut); /* Free allocated message */
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) &pOut->numObjMod, NULL, pOut,
- WTX_OBJ_MODULE_LIST, hWtx->server, WTX_SVR_SERVER)
- != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_MODULE_LIST *) &pOut->numObjMod);
- }
- /*******************************************************************************
- *
- * wtxObjModuleLoad - Load a multiple section object file
- *
- * This routine loads a module onto the target and into the target server
- * module table. The caller should pass in a pointer to a WTX_LD_M_FILE_DESC
- * structure:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_LD_M_FILE_DESC
- *
- * The user must set the `filename' field to the name of the file containing
- * the object module and the `loadFlag' to the loader flags required:
- * .iP LOAD_NO_SYMBOLS 12
- * No symbols are added to the system symbol table
- * .iP LOAD_LOCAL_SYMBOLS
- * Only local symbols are added to the system symbol table
- * .iP LOAD_GLOBAL_SYMBOLS
- * Only external symbols are added to the system symbol table
- * .iP LOAD_ALL_SYMBOLS
- * All symbols are added to the system symbol table
- * .iP LOAD_FULLY_LINKED
- * No relocation is required
- * .iP LOAD_NO_DOWNLOAD
- * The module is not loaded on the target
- * .iP LOAD_HIDDEN_MODULE
- * Load the module but make it invisible to WTX_MSG_MODULE_LIST
- * .iP LOAD_COMMON_MATCH_NONE
- * Allocate common symbols, but do not search for any matching symbols (the
- * default)
- * .iP LOAD_COMMON_MATCH_USER
- * Allocate common symbols, but search for matching symbols in user-loaded
- * modules
- * .iP LOAD_COMMON_MATCH_ALL
- * Allocate common symbols, but search for matching symbols in user-loaded
- * modules and the target-system core file
- * .iP LOAD_BAL_OPTIM
- * Use branch-and-link optimization (for i960 targets only)
- * .iP LOAD_CPLUS_XTOR_AUTO
- * C++ ctors/dtors management is explicitly turned on
- * .iP LOAD_CPLUS_XTOR_MANUAL
- * C++ ctors/dtors management is explicitly turned off
- * .iP LOAD_MODULE_INFO_ONLY
- * Create and initialize a module, do not load a file
- * .LP
- *
- * When no section description is given and `nSections' is set to zero, the
- * host-based loader allocates memory for the text, data and bss sections of
- * the module using memory from the target memory pool. If the `nSections'
- * field is non-zero, the user can specify the location to load the sections
- * and the `section' field points to an array of section descriptors:
- *
- * EXPAND ../../../include/wtxmsg.h LD_M_SECTION
- *
- * If the load is successful, the return value is a pointer to a file descriptor
- * for the new object module containing the actual information about the file
- * loaded. If there are undefined symbols in the module, `undefSymList' points
- * to a list of those symbols that were not resolved:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYM_LIST
- *
- * EXPAND ../../../include/wtxmsg.h WTX_SYMBOL
- *
- * Use free() to free the input WTX_LD_M_FILE_DESC parameter and wtxResultFree()
- * to free the output WTX_LD_M_FILE_DESC parameter.
- *
- * NOTE: COFF object modules with more than 3 sections are not supported.
- *
- * Files loaded on the target by the target server can be opened either by
- * the target server or by the client. These two behaviors can be controled by
- * <moduleId>: "WTX_LOAD_FROM_CLIENT" opens the file where the client is,
- * "WTX_LOAD_FROM_TARGET_SERVER" opens the file where the target server is.
- *
- * EXAMPLE:
- * Load a module on the target, the file is opened either by the client or by
- * the target server according to the place where the file is.
- *
- * .CS
- * ...
- *
- * pFileDescIn->filename = "/folk/pascal/Board/ads860/objSampleWtxtclTest2.o";
- * pFileDescIn->loadFlag = LOAD_GLOBAL_SYMBOLS;
- * pFileDescIn->nSections = 0;
- * pFileDescIn->moduleId = WTX_LOAD_FROM_CLIENT;
- *
- * /@ Open the file locally @/
- *
- * if (isTgtSvrLocal)
- * if((pFileDescOut = wtxObjModuleLoad (wtxh, pFileDescIn)) == NULL)
- * return (WTX_ERROR);
- * else
- * {
- * /@ Do something @/
- *
- * ...
- * }
- * }
- * else /@ The target server opens the file @/
- * {
- * pFileDescIn->moduleId = WTX_LOAD_FROM_TARGET_SERVER;
- *
- * if((pFileDescOut = wtxObjModuleLoad (wtxh, pFileDescIn)) == NULL)
- * return (WTX_ERROR);
- * else
- * {
- * /@ Do something @/
- *
- * ...
- * }
- * }
- * ...
- * .CE
- *
- * RETURNS: A pointer to a WTX_LD_M_FILE_DESC for the new module or NULL on
- * error.
- *
- * ERRORS:
- * .iP WTX_ERR_API_MEMALLOC 12
- * A buffer cannot be allocated
- * .iP WTX_ERR_API_INVALID_ARG
- * filename is NULL
- * .iP WTX_ERR_API_FILE_NOT_ACCESSIBLE
- * filename doesn't exist or bad permission
- * .iP WTX_ERR_API_FILE_NOT_FOUND
- * Cant bind the path name to the file descriptor
- * .iP WTX_ERR_API_NULL_SIZE_FILE
- * File have a null size
- * .iP WTX_ERR_API_CANT_READ_FROM_FILE
- * Read in file failed
- * .iP WTX_ERR_SVR_EINVAL
- * Request issued out of sequence. A tool should not submit a load request if
- * it already has one pending.
- * .iP WTX_ERR_SVR_NOT_ENOUGH_MEMORY
- * Cannot allocate memory for internal needs
- * .iP WTX_ERR_TGTMEM_NOT_ENOUGH_MEMORY
- * Not enough memory in the target-server-managed target memory pool to store the
- * object module segments.
- * .iP WTX_ERR_LOADER_XXX
- * See WTX_OBJ_MODULE_LOAD
- *
- * SEE ALSO: WTX_OBJ_MODULE_LOAD_2, wtxObjModuleLoad(), wtxObjModuleUnload(),
- * wtxObjModuleList(), wtxObjModuleInfoGet(), wtxObjModuleLoadStart(),
- * wtxObjModuleLoadCancel(), wtxObjModuleLoadProgressReport(),
- * .I API Reference Manual: Target Server Internal Routines,
- * .I API Programmer's Guide: Object Module Loader
- */
- WTX_LD_M_FILE_DESC * wtxObjModuleLoad
- (
- HWTX hWtx, /* WTX API handle */
- WTX_LD_M_FILE_DESC * pFileDesc /* Module descriptor */
- )
- {
- WTX_MSG_FILE_LOAD_DESC in; /* Input value */
- WTX_MSG_LD_M_FILE_DESC * pOut; /* Return value */
- WTX_ERROR_T callStat; /* Exchange return value */
- UINT32 scnIdx; /* Loop counter */
- int fileNameLen=0; /* file name length */
- #ifdef HOST
- int fd; /* File descriptor */
- int fileSize; /* Size of object module */
- int nBytes; /* Number of bytes read */
- char * buf; /* Slice of file to load */
- #ifndef WIN32
- struct stat infoFile; /* Some info on the file */
- #else
- struct _stat infoFile; /* Some info on the file */
- #endif /* WIN 32 */
- #endif /* HOST */
- WTX_CHECK_CONNECTED (hWtx, NULL);
- /* Initialize the input parameter */
- memset (&in, 0, sizeof (in));
- /* Output parameter location */
- pOut = (WTX_MSG_LD_M_FILE_DESC *) calloc (1,
- sizeof (WTX_MSG_LD_M_FILE_DESC));
- if (pOut == NULL)
- {
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- pOut->wtxCore.protVersion = (UINT32) pOut;
- /*
- * This ack is used to prevent garbage bits in moduleId :
- * - user can only set WTX_LOAD_FROM_XXX
- * - we can use WTX_LOAD_ASYNCHRONOUSLY & WTX_LOAD_PROGRESS_REPORT
- */
- if (!internalLoadCall)
- pFileDesc->moduleId &= WTX_LOAD_FROM_TARGET_SERVER;
- else
- internalLoadCall = FALSE;
- /* Set the asynchronous / progress report load flag if needed */
- if (pFileDesc->moduleId == WTX_LOAD_PROGRESS_REPORT)
- {
- wtxErrClear (hWtx);
- in.flags = WTX_LOAD_PROGRESS_REPORT;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_LOAD_2, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- if (pOut->loadFlag == WTX_ERR_LOADER_LOAD_IN_PROGRESS)
- {
- wtxErrSet (hWtx, WTX_ERR_LOADER_LOAD_IN_PROGRESS);
- }
- if (wtxFreeAdd (hWtx, (void *) ((int) pOut +
- OFFSET (WTX_MSG_DUMMY, field)),
- NULL, pOut, WTX_OBJ_MODULE_LOAD_2, hWtx->server,
- WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- /* Output parameter */
- return ((WTX_LD_M_FILE_DESC *) ((int) pOut +
- OFFSET (WTX_MSG_DUMMY, field)));
- }
- if (pFileDesc->moduleId & WTX_LOAD_ASYNCHRONOUSLY)
- {
- in.flags = WTX_LOAD_ASYNCHRONOUSLY;
- }
- else
- {
- in.flags = 0;
- }
- /* Set the input structure */
- if (pFileDesc->filename == NULL)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, NULL);
- }
- /* allocate room for the file name string */
- fileNameLen = strlen (pFileDesc->filename) + 1;
- if ( (in.fileDesc.filename = (char *) malloc (fileNameLen)) == NULL)
- {
- free (pOut);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- strcpy (in.fileDesc.filename, pFileDesc->filename);
- if (pFileDesc->nSections != 0)
- {
- in.fileDesc.section = (LD_M_SECTION *) calloc (1,
- pFileDesc->nSections * sizeof (LD_M_SECTION));
- if (in.fileDesc.section == NULL)
- {
- free (pOut);
- free (in.fileDesc.filename);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- for (scnIdx = 0; scnIdx < pFileDesc->nSections; scnIdx++)
- in.fileDesc.section [scnIdx].addr =
- pFileDesc->section [scnIdx].addr;
- }
- else
- in.fileDesc.section = NULL;
- memset ((void *) &in.fileDesc.undefSymList, 0, sizeof (WTX_SYM_LIST));
- in.wtxCore.errCode = 0;
- in.wtxCore.protVersion = 0;
- in.fileDesc.moduleId = 0;
- in.fileDesc.loadFlag = pFileDesc->loadFlag;
- in.fileDesc.nSections = pFileDesc->nSections;
- in.numPacket = 0;
- /* The file must be opened by the target server */
- if ((pFileDesc->moduleId & WTX_LOAD_FROM_TARGET_SERVER) ||
- ((pFileDesc->loadFlag & LOAD_MODULE_INFO_ONLY)
- == LOAD_MODULE_INFO_ONLY))
- {
- in.buffer = NULL;
- in.numItems = 0;
- in.fileSize = 0;
- in.numPacket = 0;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_LOAD_2, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- /* Output parameter */
- if (wtxFreeAdd (hWtx, (void *) ((int) pOut + OFFSET (WTX_MSG_DUMMY,
- field)),
- NULL, pOut, WTX_OBJ_MODULE_LOAD_2, hWtx->server,
- WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- return ((WTX_LD_M_FILE_DESC *) ((int) pOut +
- OFFSET (WTX_MSG_DUMMY, field)));
- }
- /* Open object module file */
- #ifdef HOST
- #ifdef WIN32
- if((fd = open (pFileDesc->filename, O_RDONLY | _O_BINARY, 0)) == ERROR)
- #else /* WIN32 */
- if((fd = open (pFileDesc->filename, O_RDONLY , 0)) == ERROR)
- #endif /* WIN32 */
- {
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_FILE_NOT_ACCESSIBLE, NULL);
- }
- /* Bind the path to the file descriptor */
- if (pathFdBind (fd, pFileDesc->filename) == ERROR)
- {
- close (fd);
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_FILE_NOT_FOUND, NULL);
- }
- /* Get the object file size */
- #ifndef WIN32
- if (fstat (fd, &infoFile) != OK)
- #else
- if (_fstat (fd, &infoFile) != OK)
- #endif /* WIN32 */
- {
- close (fd);
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_FILE_NOT_ACCESSIBLE, NULL);
- }
- fileSize = (int) infoFile.st_size;
- if (fileSize == 0)
- {
- close (fd);
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_NULL_SIZE_FILE, NULL);
- }
- /* Set the input structure */
- in.fileSize = fileSize;
- do
- {
- /* Malloc on buf to store a part of the file */
- buf = (char *) calloc (WTX_FILE_SLICE_SIZE, sizeof(char));
- if (buf == NULL)
- {
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_MEMALLOC, NULL);
- }
- /* The object file is read and stored in the host memory */
- nBytes = read (fd, buf, WTX_FILE_SLICE_SIZE);
- if (nBytes == ERROR)
- {
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- free (buf);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_CANT_READ_FROM_FILE, NULL);
- }
- /* EOF reached: exit while loop */
- if (nBytes == 0)
- {
- free (buf);
- break;
- }
- in.numPacket++;
- in.numItems = nBytes;
- in.buffer = buf;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_LOAD_2, &in, pOut);
- if (callStat != WTX_ERR_NONE)
- {
- free (buf);
- free (pOut);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- WTX_ERROR_RETURN (hWtx, callStat, NULL);
- }
- free (buf);
- /* One more time if more events to display */
- } while (nBytes != 0);
- /* Close the file */
- close (fd);
- free (in.fileDesc.filename);
- if (in.fileDesc.section != NULL)
- free (in.fileDesc.section);
- /* add pointer to the wtxResultFree () list */
- if (wtxFreeAdd (hWtx, (void *) ((int) pOut + OFFSET (WTX_MSG_DUMMY, field)),
- NULL, pOut, WTX_OBJ_MODULE_LOAD_2, hWtx->server,
- WTX_SVR_SERVER) != WTX_OK)
- {
- WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- }
- #endif /* HOST */
- /* Output parameter */
- return ((WTX_LD_M_FILE_DESC *) ((int) pOut +
- OFFSET (WTX_MSG_DUMMY, field)));
- }
- /*******************************************************************************
- *
- * wtxObjModuleLoadStart - Load a multiple section object file asynchronously
- *
- * This routine loads a module onto the target and into the target server
- * module table. It returns when the module is in the target server memory,
- * ready to be relocated and downloaded by the target server loader.
- * The caller should pass in a pointer to a WTX_LD_M_FILE_DESC structure:
- *
- * EXPAND ../../../include/wtxmsg.h WTX_LD_M_FILE_DESC
- *
- * The user must set the `filename' field to the name of the file containing
- * the object module and the `loadFlag' to the loader flags required:
- * .iP LOAD_NO_SYMBOLS 12
- * No symbols are added to the system symbol table
- * .iP LOAD_LOCAL_SYMBOLS
- * Only local symbols are added to the system symbol table
- * .iP LOAD_GLOBAL_SYMBOLS
- * Only external symbols are added to the system symbol table
- * .iP LOAD_ALL_SYMBOLS
- * All symbols are added to the system symbol table
- * .iP LOAD_FULLY_LINKED
- * No relocation is required
- * .iP LOAD_NO_DOWNLOAD
- * The module is not loaded on the target
- * .iP LOAD_HIDDEN_MODULE
- * Load the module but make it invisible to WTX_MSG_MODULE_LIST
- * .iP LOAD_COMMON_MATCH_NONE
- * Allocate common symbols, but do not search for any matching symbols (the
- * default)
- * .iP LOAD_COMMON_MATCH_USER
- * Allocate common symbols, but search for matching symbols in user-loaded
- * modules
- * .iP LOAD_COMMON_MATCH_ALL
- * Allocate common symbols, but search for matching symbols in user-loaded
- * modules and the target-system core file
- * .iP LOAD_BAL_OPTIM
- * Use branch-and-link optimization (for i960 targets only)
- * .iP LOAD_CPLUS_XTOR_AUTO
- * C++ ctors/dtors management is explicitly turned on
- * .iP LOAD_CPLUS_XTOR_MANUAL
- * C++ ctors/dtors management is explicitly turned off
- * .iP LOAD_MODULE_INFO_ONLY
- * Create and initialize a module, do not load a file
- * .LP
- *
- * When no section description is given and `nSections' is set to zero, the
- * host-based loader allocates memory for the text, data and bss sections of
- * the module using memory from the target memory pool. If the `nSections'
- * field is non-zero, the user can specify the location to load the sections
- * and the `section' field points to an array of section descriptors:
- *
- * EXPAND ../../../include/wtxmsg.h LD_M_SECTION
- *
- * NOTE: COFF object modules with more than 3 sections are not supported.
- *
- * NOTE: Because this routine returns only WTX_OK or WTX_ERROR, the user
- * must call wtxObjModuleLoadProgressReport() in order to have the module Id,
- * sections addresses and the undefined symbols.
- *
- * Files loaded on the target by the target server can be opened either by
- * the target server or by the client. These two behaviors can be controled by
- * <moduleId>: "WTX_LOAD_FROM_CLIENT" opens the file where the client is,
- * "WTX_LOAD_FROM_TARGET_SERVER" opens the file where the target server is.
- *
- * EXAMPLE:
- * Load a module on the target, the file is opened either by the client or by
- * the target server according to the place where the file is.
- *
- * .CS
- * ...
- *
- * pFileDescIn->filename = "/folk/pascal/Board/ads860/objSampleWtxtclTest2.o";
- * pFileDescIn->loadFlag = LOAD_GLOBAL_SYMBOLS;
- * pFileDescIn->nSections = 0;
- * pFileDescIn->moduleId = WTX_LOAD_FROM_CLIENT;
- *
- * /@ Open the file locally @/
- *
- * if (isTgtSvrLocal)
- * {
- * if(wtxObjModuleLoadStart (wtxh, pFileDescIn) == WTX_ERROR)
- * return (WTX_ERROR);
- * else
- * {
- * /@ Load is in progress: get its status @/
- *
- * if ((pLoadReport = wtxObjModuleLoadProgressReport (wtxh)) == NULL)
- * return (WTX_ERROR);
- *
- * /@ Do something @/
- *
- * ...
- * }
- * }
- * else /@ The target server opens the file @/
- * {
- * pFileDescIn->moduleId = WTX_LOAD_FROM_TARGET_SERVER;
- *
- * if(wtxObjModuleLoadStart (wtxh, pFileDescIn) == WTX_ERROR)
- * return (WTX_ERROR);
- * else
- * {
- * /@ Load is in progress: get its status @/
- *
- * if ((pLoadReport = wtxObjModuleLoadProgressReport (wtxh)) == NULL)
- * return (WTX_ERROR);
- *
- * /@ Do something @/
- *
- * ...
- * }
- * }
- * ...
- * .CE
- *
- * RETURNS: WTX_OK or WTX_ERROR if something failed
- *
- * ERRORS:
- * .iP WTX_ERR_API_MEMALLOC 12
- * A buffer cannot be allocated
- * .iP WTX_ERR_API_INVALID_ARG
- * filename is NULL
- * .iP WTX_ERR_API_FILE_NOT_ACCESSIBLE
- * filename doesn't exist or bad permission
- * .iP WTX_ERR_API_FILE_NOT_FOUND
- * Cant bind the path name to the file descriptor
- * .iP WTX_ERR_API_NULL_SIZE_FILE
- * File have a null size
- * .iP WTX_ERR_API_CANT_READ_FROM_FILE
- * Read in file failed
- * .iP WTX_ERR_SVR_EINVAL
- * Request issued out of sequence. A tool should not submit a load request if
- * it already has one pending.
- * .iP WTX_ERR_SVR_NOT_ENOUGH_MEMORY
- * Cannot allocate memory for internal needs
- * .iP WTX_ERR_TGTMEM_NOT_ENOUGH_MEMORY
- * Not enough memory in the target-server-managed target memory pool to store the
- * object module segments.
- * .iP WTX_ERR_LOADER_XXX
- * See WTX_OBJ_MODULE_LOAD
- *
- * SEE ALSO: WTX_OBJ_MODULE_LOAD_2, wtxObjModuleLoad(),
- * wtxObjModuleLoadProgressReport(), wtxObjModuleLoadCancel(),
- * .I API Reference Manual: Target Server Internal Routines,
- * .I API Programmer's Guide: Object Module Loader
- */
- STATUS wtxObjModuleLoadStart
- (
- HWTX hWtx, /* WTX API handle */
- WTX_LD_M_FILE_DESC * pFileDesc /* Module descriptor */
- )
- {
- #ifdef HOST
- WTX_LD_M_FILE_DESC * result;
- /* Keep only WTX_LOAD_FROM_XXX bits */
- pFileDesc->moduleId &= WTX_LOAD_FROM_TARGET_SERVER;
- /* module info request will be reported synchronously */
- if (pFileDesc->loadFlag & LOAD_MODULE_INFO_ONLY)
- pFileDesc->moduleId &= (~WTX_LOAD_ASYNCHRONOUSLY);
- else
- pFileDesc->moduleId |= WTX_LOAD_ASYNCHRONOUSLY;
- internalLoadCall = TRUE;
- result = wtxObjModuleLoad (hWtx, pFileDesc);
- if (result == NULL)
- return (WTX_ERROR);
- /* Free allocated memory */
- wtxResultFree (hWtx, result);
- #endif /* HOST */
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxObjModuleLoadProgressReport - get the asynchronous load status
- *
- * This routine returns the current load context after a wtxObjModuleLoadStart
- * request.
- *
- * EXPAND ../../../include/wtx.h WTX_LOAD_REPORT_INFO
- *
- * Use free() to free the output WTX_LOAD_REPORT_INFO parameter, and when
- * the load is complete, use wtxSymListFree() to free the undefined symbols
- * list if it exists, free also <filename> and <section>.
- *
- * EXAMPLE:
- * Load a module on the target and each second, the load status is evaluated.
- *
- * .CS
- * ...
- *
- * pFileDescIn->filename = "/folk/pascal/Board/ads860/big.o";
- * pFileDescIn->loadFlag = LOAD_GLOBAL_SYMBOLS;
- * pFileDescIn->nSections = 0;
- *
- * /@ Load the module asynchronously @/
- *
- * if (wtxObjModuleLoadStart (wtxh, pFileDescIn) == WTX_ERROR)
- * return (WTX_ERROR);
- *
- * /@ Get info about the load @/
- *
- * if ((pLoadReport = wtxObjModuleLoadProgressReport (wtxh)) == NULL)
- * return (WTX_ERROR)
- * else
- * {
- * /@ Define some shorthands @/
- *
- * #define progress pLoadReport->STATE_INFO.PROGRESS_INFO
- * #define mod pLoadReport->STATE_INFO.WTX_LD_M_FILE_DESC
- *
- * while (pLoadReport->loadState == LOAD_IN_PROGRESS)
- * {
- * #ifdef WIN32
- * Sleep (1000);
- * #else
- * sleep (1);
- * #endif
- *
- * /@ Print info about the load request @/
- *
- * printf ("ttLOAD_IN_PROGRESS");
- * printf ("tPHASE: %dtdone: %dtremaining: %dn",
- * progress.state, progress.currentValue,
- * progress.maxValue - progress.currentValue);
- *
- * free (pLoadReport);
- *
- * if ((pLoadReport = wtxObjModuleLoadProgressReport (wtxh)) == NULL)
- * {
- * printf ("nwtxObjModuleProgressReport failedn");
- * return (WTX_ERROR);
- * }
- * }
- *
- * /@ The load is done: the module is on the target @/
- *
- * printf ("ttLOAD_DONEn");
- *
- * /@ Do something @/
- *
- * ...
- *
- * /@ First free any symbols list @/
- *
- * wtxSymListFree (&pLoadReport->undefSymList);
- *
- * /@ Feeing dynamically allocated memory @/
- *
- * if (pLoadReport->filename != NULL)
- * free (pLoadReport->filename);
- *
- * if (pLoadReport->section != NULL)
- * free (pLoadReport->section);
- *
- * free (pLoadReport);
- *
- * ...
- * .CE
- *
- * RETURNS: A pointer to a WTX_LOAD_REPORT_INFO for the load status or NULL on
- * error.
- *
- * ERRORS:
- * .iP WTX_ERR_API_MEMALLOC 12
- * A buffer cannot be allocated
- * .iP WTX_ERR_API_INVALID_ARG
- * An invalid argument had been received
- * .iP WTX_ERR_LOADER_LOAD_CANCELED
- * The load had been aborted
- * .iP WTX_ERR_LOADER_LOAD_IN_PROGRESS
- * The load operation is not finished
- * .iP WTX_ERR_LOADER_OBJ_MODULE_NOT_FOUND
- * The module was unloaded by another client
- * .iP WTX_ERR_SVR_EINVAL
- * Request issued out of sequence. A tool should submit a load before issuing
- * this request.
- * .iP WTX_ERR_SVR_NOT_ENOUGH_MEMORY
- * Cannot allocate memory for internal needs
- * .iP WTX_ERR_TGTMEM_NOT_ENOUGH_MEMORY
- * Not enough memory in the target-server-managed target memory pool to store the
- * object module segments.
- * .iP WTX_ERR_LOADER_XXX
- * See WTX_OBJ_MODULE_LOAD
- *
- * SEE ALSO: WTX_OBJ_MODULE_LOAD_2, wtxObjModuleLoadStart(),
- * wtxObjModuleLoad(), wtxObjModuleLoadCancel(),
- * .I API Reference Manual: Target Server Internal Routines,
- * .I API Programmer's Guide: Object Module Loader
- */
- WTX_LOAD_REPORT_INFO * wtxObjModuleLoadProgressReport
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- WTX_LOAD_REPORT_INFO * pReportInfo = NULL; /* load progress info */
- #ifdef HOST
- WTX_LD_M_FILE_DESC * pFileDescIn = NULL; /* load action spec */
- WTX_LD_M_FILE_DESC * pFileDescOut = NULL; /* load result info */
- UINT32 index; /* index counter */
- #define progress pReportInfo->STATE_INFO.PROGRESS_INFO
- #define mod pReportInfo->STATE_INFO.WTX_LD_M_FILE_DESC
- /* Allocate memory to store the input / output parameters */
- if ( (pReportInfo = (WTX_LOAD_REPORT_INFO *)
- calloc (1, sizeof (WTX_LOAD_REPORT_INFO))) == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- if ( (pFileDescIn = (WTX_LD_M_FILE_DESC *)
- calloc (1, sizeof (WTX_LD_M_FILE_DESC))) == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- /* Tell wtxObjModuleLoad() that we are in a PROGRESS_REPORT request */
- pFileDescIn->moduleId = WTX_LOAD_PROGRESS_REPORT;
- internalLoadCall = TRUE;
- /* Do the call */
- pFileDescOut = wtxObjModuleLoad (hWtx, pFileDescIn);
- /* Something failed during the call */
- if (pFileDescOut == NULL)
- {
- goto error;
- }
- /* We have an error, it's OK : this is the answer of PROGRESS_REPORT */
- if (wtxErrGet (hWtx) == WTX_ERR_LOADER_LOAD_IN_PROGRESS)
- {
- /* If we have more than 1 section, it's an error */
- if (pFileDescOut->nSections != 1)
- {
- wtxErrSet (hWtx, WTX_ERR_API_INVALID_ARG);
- goto error;
- }
- /* Save the progress report info values */
- pReportInfo->loadState = LOAD_IN_PROGRESS;
- progress.state = pFileDescOut->section[0].flags;
- progress.maxValue = pFileDescOut->section[0].addr;
- progress.currentValue = pFileDescOut->section[0].length;
- /* XXX - pai:
- * Note that if this mod is accepted, it changes the API
- * and breaks code which uses this routine as documented
- * in the comment header. Expect runtime errors if the
- * following mod is compiled in.
- *
- * /@ add the pointer to the wtxResultFree() list @/
- *
- * if (wtxFreeAdd (hWtx, (void *) pReportInfo, (FUNCPTR) free, NULL, 0,
- * NULL, WTX_SVR_NONE) != WTX_OK)
- * {
- * WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- * }
- */
- }
- else
- {
- /* Otherwise, the load is done */
- pReportInfo->loadState = LOAD_DONE;
- /* Copy the info from wtxObjModuleLoad */
- mod.loadFlag = pFileDescOut->loadFlag;
- mod.moduleId = pFileDescOut->moduleId;
- mod.nSections = pFileDescOut->nSections;
- /* Copy the file name */
- if ((mod.filename = calloc (strlen (pFileDescOut->filename) + 1, 1))
- == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- strcpy (mod.filename, pFileDescOut->filename);
- /* Copy the sections */
- if ((mod.section = calloc (mod.nSections * sizeof (LD_M_SECTION) , 1))
- == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- for (index = 0; index < mod.nSections; index++)
- {
- mod.section[index].flags = pFileDescOut->section[index].flags;
- mod.section[index].addr = pFileDescOut->section[index].addr;
- mod.section[index].length = pFileDescOut->section[index].length;
- }
-
- /* Copy the undefined symbols list */
- if (pFileDescOut->undefSymList.pSymbol != NULL)
- {
- WTX_SYMBOL * pSymbol; /* symbol in XDR list */
- WTX_SYMBOL * pCurrent; /* newly allocated symbol */
- WTX_SYMBOL * pPrevious = NULL; /* previous symbol */
- BOOL firstSymbol = TRUE; /* first symbol in list ? */
- for (pSymbol = pFileDescOut->undefSymList.pSymbol; pSymbol;
- pSymbol = (WTX_SYMBOL *) pSymbol->next)
- {
- if ((pCurrent = (WTX_SYMBOL *) calloc (1, sizeof (WTX_SYMBOL)))
- == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- memcpy ((void *) pCurrent, (void *) pSymbol,
- sizeof (WTX_SYMBOL));
- if ((pCurrent->name = calloc (strlen (pSymbol->name) + 1,
- sizeof (char))) == NULL)
- {
- wtxErrSet (hWtx, WTX_ERR_API_MEMALLOC);
- goto error;
- }
- strcpy (pCurrent->name, pSymbol->name);
- pCurrent->next = NULL;
- if (firstSymbol)
- {
- mod.undefSymList.pSymbol = pCurrent;
- firstSymbol = FALSE;
- }
- else
- pPrevious->next = pCurrent;
- pPrevious = pCurrent;
- }
- }
- /* XXX - pai:
- * Note that if this mod is accepted, it changes the API
- * and breaks code which uses this routine as documented
- * in the comment header. Expect runtime errors if the
- * following mod is compiled in.
- *
- * /@ add the pointer to the wtxResultFree() list @/
- *
- * if (wtxFreeAdd (hWtx, (void *) pReportInfo,
- * (FUNCPTR) wtxObjModuleLoadProgressReportFree, NULL, 0,
- * NULL, WTX_SVR_NONE) != WTX_OK)
- * {
- * WTX_ERROR_RETURN (hWtx, wtxErrGet (hWtx), NULL);
- * }
- */
- }
- /* Free allocated memory */
- free (pFileDescIn);
- wtxResultFree (hWtx, pFileDescOut);
- #endif /* HOST */
-
- /* Output parameter */
- return (pReportInfo);
- #ifdef HOST
- error:
- if (pFileDescIn != NULL)
- free (pFileDescIn);
- if (mod.filename != NULL)
- free (mod.filename);
- if (mod.section != NULL)
- free (mod.section);
- wtxSymListFree (&mod.undefSymList);
- if (pReportInfo != NULL)
- free (pReportInfo);
-
- wtxResultFree (hWtx, pFileDescOut);
- return (NULL);
- #endif /* HOST */
- }
- #if 0
- /* XXX : fle : for SRP#67326 */
- #ifdef HOST
- /*******************************************************************************
- *
- * wtxObjModuleLoadProgressReportFree - free a load status report
- *
- * This routine is to free a load status report that is in the LOAD_DONE state.
- * It is only applicable for LOAD_DONE states.
- *
- * RETURNS: WTX_OK or WTX_ERROR on failure
- */
- LOCAL STATUS wtxObjModuleLoadProgressReportFree
- (
- HWTX hWtx, /* WTX session handler */
- WTX_LOAD_REPORT_INFO * pToFree /* pointer to free */
- )
- {
- STATUS status = WTX_ERROR; /* function status */
- if ( (pToFree == NULL) || (pToFree->loadState != LOAD_DONE))
- {
- /* one of the given arguments is invalid */
- wtxErrSet (hWtx, WTX_ERR_API_INVALID_ARG);
- goto error;
- }
- #define desc pToFree->STATE_INFO.WTX_LD_M_FILE_DESC
- if (desc.filename !=NULL)
- {
- free (desc.filename);
- }
- if (desc.section != NULL)
- {
- free (desc.section);
- }
- if (&desc.undefSymList != NULL)
- {
- wtxSymListFree (&desc.undefSymList);
- }
- free (pToFree);
- /* all the free operations went all right, exit with WTX_OK */
- status = WTX_OK;
- error:
- return (status);
- }
- #endif /* HOST */
- #endif /* 0 */
- /*******************************************************************************
- *
- * wtxObjModuleLoadCancel - Stop an asynchronous load request
- *
- * This routine stops an asynchronous load request. If the load had been
- * already done or it can't be found, then it returns an error.
- *
- * RETURNS: WTX_OK or WTX_ERROR on error.
- *
- * ERRORS:
- * .iP WTX_ERR_SVR_INVALID_CLIENT_ID 12
- * Tool not registered
- * .iP WTX_ERR_SVR_EINVAL
- * Request issued out of sequence. A tool should submit a load before issuing
- * this request.
- * .iP WTX_ERR_LOADER_ALREADY_LOADED
- * The load is already finished
- *
- * SEE ALSO: WTX_COMMAND_SEND, wtxObjModuleLoadStart(),
- * wtxObjModuleLoadProgressReport(),
- * .I API Reference Manual: Target Server Internal Routines,
- * .I API Programmer's Guide: Object Module Loader
- */
- STATUS wtxObjModuleLoadCancel
- (
- HWTX hWtx /* WTX API handle */
- )
- {
- #ifdef HOST
- WTX_ERROR_T callStat; /* Exchange result */
- WTX_MSG_PARAM in; /* Query parameters */
- WTX_MSG_RESULT out; /* Query result */
- char buf [32]; /* Input buffer */
- /*
- * All API calls that require a connection to the target server
- * should use the WTX_CHECK_CONNECTED macro before doing anything else.
- * This macro also calls WTX_CHECK_HANDLE to validate the handle.
- */
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- /* Set input - ouput parameters for WTX_COMMAND_SEND */
- in.param.valueType = V_PCHAR;
- strcpy (buf, WTX_LOAD_CANCEL_CMD);
- in.param.value_u.v_pchar = buf;
- memset (&out, 0, sizeof (out));
- /* Call WTX_COMMAND_SEND - wtxObjModuleLoadCancel service */
- callStat = exchange (hWtx, WTX_COMMAND_SEND, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_COMMAND_SEND, &out);
- #endif /* HOST */
- /* Tchao */
- return (WTX_OK);
- }
- /******************************************************************************
- *
- * wtxObjModuleUndefSymAdd - add a undefined symbol to the undefined symbol list
- *
- * This routine adds the symbol specified by <symId> to the corresponding
- * module's undefined symbol list.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_OBJ_MODULE_UNDEF_SYM_ADD
- * NOMANUAL
- */
- STATUS wtxObjModuleUndefSymAdd
- (
- HWTX hWtx, /* WTX API handle */
- char * symName, /* undefined symbol name */
- UINT32 symGroup /* undefined symbol group */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_SYMBOL_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.symbol.name = symName;
- in.symbol.group = symGroup;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_UNDEF_SYM_ADD, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_MODULE_UNDEF_SYM_ADD, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxObjModuleUnload - unload an object module from the target
- *
- * This routine unloads the module specified by <moduleId> from the target.
- * The module ID is returned when the module is loaded or by one of the
- * information routines.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_OBJ_MODULE_UNLOAD_2, wtxObjModuleLoad(), wtxObjModuleList(),
- * wtxObjModuleInfoGet()
- */
- STATUS wtxObjModuleUnload
- (
- HWTX hWtx, /* WTX API handle */
- UINT32 moduleId /* id of module to unload */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.filename = NULL;
- in.moduleId = moduleId;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_UNLOAD_2, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_MODULE_UNLOAD_2, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxObjModuleByNameUnload - unload an object module from the target
- *
- * This routine unloads the module specified by <name> from the target.
- * The module ID is returned when the module is loaded or by one of the
- * information routines.
- *
- * RETURNS: WTX_OK or WTX_ERROR if exchange failed.
- *
- * SEE ALSO: WTX_OBJ_MODULE_UNLOAD_2, wtxObjModuleUnload(),
- * wtxObjModuleLoad(), wtxObjModuleList(), wtxObjModuleInfoGet()
- */
- STATUS wtxObjModuleByNameUnload
- (
- HWTX hWtx, /* WTX API handle */
- char * name /* Name of module to look for */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_MOD_NAME_OR_ID in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&in, 0, sizeof (in));
- memset (&out, 0, sizeof (out));
- in.filename = name;
- in.moduleId = 0;
- callStat = exchange (hWtx, WTX_OBJ_MODULE_UNLOAD_2, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_OBJ_MODULE_UNLOAD_2, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxRegisterForEvent - ask the WTX server to send events matching a regexp
- *
- * This routine takes a string <regExp>, which is a regular expression,
- * and uses it to specify which events this user is interested in. By
- * default a WTX client receives no event notifications.
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_REGISTER_FOR_EVENT, wtxUnregisterForEvent(),
- * wtxEventGet(), wtxEventListGet()
- */
- STATUS wtxRegisterForEvent
- (
- HWTX hWtx, /* WTX API handle */
- const char * regExp /* Regular expression to select events */
- )
- {
- WTX_ERROR_T callStat;
- WTX_MSG_EVENT_REG_DESC in;
- WTX_MSG_RESULT out;
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- in.evtRegExp = (char *) regExp;
- callStat = exchange (hWtx, WTX_REGISTER_FOR_EVENT, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_REGISTER_FOR_EVENT, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxRegsGet - read register data from the target
- *
- * This routine reads <numBytes> of raw (target format) register data
- * from the register set <regSet> starting from the byte at offset
- * <firstByte>. The data read are stored in local memory at <regMemory>.
- *
- * The context types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_CONTEXT_TYPE
- *
- * EXPAND ../../../include/wtxtypes.h WTX_REG_SET_TYPE
- *
- * RETURNS: WTX_OK or WTX_ERROR.
- *
- * SEE ALSO: WTX_REGS_GET, wtxRegsSet()
- */
- STATUS wtxRegsGet
- (
- HWTX hWtx, /* WTX API handle */
- WTX_CONTEXT_TYPE contextType, /* context type to get regs of */
- WTX_CONTEXT_ID_T contextId, /* context id to get regs of */
- WTX_REG_SET_TYPE regSet, /* type of register set */
- UINT32 firstByte, /* first byte of register set */
- UINT32 numBytes, /* number of bytes of register set */
- void * regMemory /* place holder for reg. values */
- )
- {
- WTX_MSG_MEM_XFER_DESC out;
- WTX_MSG_REG_READ in;
- WTX_ERROR_T callStat;
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- in.context.contextType = contextType;
- in.context.contextId = contextId;
- in.regSetType = regSet;
- in.memRegion.baseAddr = (TGT_ADDR_T) firstByte;
- in.memRegion.size = numBytes;
- /* NOTE: This relies on XDR to allocate memory to write register info to */
- callStat = exchange (hWtx, WTX_REGS_GET, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- /* WTX_REGS_GET is a pain because it may not set the error flag */
- if (out.memXfer.numBytes != numBytes)
- {
- wtxExchangeFree (hWtx->server, WTX_REGS_GET, &out);
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_REGS_GET_PARTIAL_READ, WTX_ERROR);
- }
-
- memcpy(regMemory, out.memXfer.source, out.memXfer.numBytes);
- wtxExchangeFree (hWtx->server, WTX_REGS_GET, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxRegsSet - write to registers on the target
- *
- * This routine writes <numBytes> of raw (target format) register data
- * to register set <regSet> starting at offset <firstByte>. Data is
- * written from local memory at <regMemory>.
- *
- * The context types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_CONTEXT_TYPE
- *
- * EXPAND ../../../include/wtxtypes.h WTX_REG_SET_TYPE
- *
- * RETURNS: WTX_OK or WTX_ERROR if the register set fails.
- *
- * SEE ALSO: WTX_REGS_SET
- */
- STATUS wtxRegsSet
- (
- HWTX hWtx, /* WTX API handle */
- WTX_CONTEXT_TYPE contextType, /* context type to set regs of */
- WTX_CONTEXT_ID_T contextId, /* context id to set regs of */
- WTX_REG_SET_TYPE regSet, /* type of register set */
- UINT32 firstByte, /* first byte of reg. set */
- UINT32 numBytes, /* number of bytes in reg. set. */
- void * regMemory /* register contents */
- )
- {
- WTX_MSG_RESULT out;
- WTX_MSG_REG_WRITE in;
- WTX_ERROR_T callStat;
-
- WTX_CHECK_CONNECTED (hWtx, WTX_ERROR);
- memset (&out, 0, sizeof (out));
- memset (&in, 0, sizeof (in));
- in.context.contextId = contextId;
- in.context.contextType = contextType;
- in.regSetType = regSet;
- in.memXfer.destination = (TGT_ADDR_T) firstByte;
- in.memXfer.numBytes = numBytes;
- in.memXfer.source = (char *) regMemory;
-
- callStat = exchange (hWtx, WTX_REGS_SET, &in, &out);
- if (callStat != WTX_ERR_NONE)
- WTX_ERROR_RETURN (hWtx, callStat, WTX_ERROR);
- wtxExchangeFree (hWtx->server, WTX_REGS_SET, &out);
- return (WTX_OK);
- }
- /*******************************************************************************
- *
- * wtxStrToTgtAddr - convert a string argument to a TGT_ADDR_T value
- *
- * This routine takes a string and converts it to a TGT_ADDR_T. The string
- * is part of an event string. See wtxEventGet() and the WTX library
- * discussion of WTX events in the f2API Reference Manual: WTX ProtocolfP.
- *
- * RETURNS: The address as a TGT_ADDR_T value.
- */
- TGT_ADDR_T wtxStrToTgtAddr
- (
- HWTX hWtx, /* WTX API handle */
- const char *str /* string */
- )
- {
- WTX_CHECK_HANDLE (hWtx, 0);
- return (TGT_ADDR_T) strtoul (str, NULL, 16); /* Base 16 read */
- }
- /*******************************************************************************
- *
- * wtxStrToContextId - convert a string argument to a WTX_CONTEXT_ID_T
- *
- * This routine takes a string and converts it to a context ID. The string
- * is part of an event string. See wtxEventGet() and the WTX library
- * discussion of WTX events in the f2API Reference Manual: WTX ProtocolfP.
- *
- * RETURNS: The context ID.
- */
- WTX_CONTEXT_ID_T wtxStrToContextId
- (
- HWTX hWtx, /* WTX API handle */
- const char *str /* string */
- )
- {
- WTX_CHECK_HANDLE (hWtx, 0);
- return (WTX_CONTEXT_ID_T) strtoul (str, NULL, 16); /* Hex read */
- }
- /*******************************************************************************
- *
- * wtxStrToContextType - convert a string argument to a WTX_CONTEXT_TYPE value
- *
- * This routine takes a string and converts it to a WTX_CONTEXT_TYPE
- * enumeration value. The string is part of an event string. See
- * wtxEventGet() and the WTX library discussion of WTX events in the f2API
- * Reference Manual: WTX ProtocolfP.
- *
- * The context types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_CONTEXT_TYPE
- *
- * RETURNS: The context type or WTX_ERROR on error.
- */
- WTX_CONTEXT_TYPE wtxStrToContextType
- (
- HWTX hWtx, /* WTX API handle */
- const char * str /* string */
- )
- {
- INT32 value;
- WTX_CHECK_HANDLE (hWtx, WTX_ERROR);
- value = (INT32) strtol (str, NULL, 16); /* Hex read */
-
- if (value < WTX_CONTEXT_SYSTEM || value > WTX_CONTEXT_ISR_ANY)
- WTX_ERROR_RETURN (hWtx, WTX_ERR_API_INVALID_ARG, WTX_ERROR);
- else
- return (WTX_CONTEXT_TYPE) value;
- }
- /*******************************************************************************
- *
- * wtxStrToInt32 - convert a string argument to an INT32 value
- *
- * This routine takes a string and converts it to a signed host integer. The
- * string is part of an event string. See wtxEventGet() and the WTX library
- * discussion of WTX events in the f2API Reference Manual: WTX ProtocolfP.
- *
- * RETURNS: The string as an INT32 value.
- */
- INT32 wtxStrToInt32
- (
- HWTX hWtx, /* WTX API handle */
- const char *str /* string */
- )
- {
- return (INT32) strtol (str, NULL, 16); /* Base 16 read */
- }
- /*******************************************************************************
- *
- * wtxStrToEventType - convert a string to a WTX event enumeration type
- *
- * This routine is a type converter for the event strings passed
- * to a WTX client by the target server. It converts back to the
- * event enumeration type so event types can be switched on.
- *
- * If the string is NULL, WTX_EVT_T_NONE is returned. If
- * the string does not match any of the pre-defined events,
- * WTX_EVT_T_OTHER is returned.
- *
- * The event types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_EVENT_TYPE
- *
- * RETURNS: The event type or WTX_EVT_T_INVALID on error.
- */
- WTX_EVENT_TYPE wtxStrToEventType
- (
- HWTX hWtx, /* WTX API handle */
- const char *str /* string */
- )
- {
- WTX_CHECK_HANDLE (hWtx, WTX_EVENT_INVALID);
- if (str == NULL)
- return WTX_EVENT_NONE;
- else if (STREQ (str, WTX_EVT_TGT_RESET))
- return WTX_EVENT_TGT_RESET;
- else if (STREQ (str, WTX_EVT_SYM_ADDED))
- return WTX_EVENT_SYM_ADDED;
- else if (STREQ (str,WTX_EVT_SYM_REMOVED))
- return WTX_EVENT_SYM_REMOVED;
- else if (STREQ (str,WTX_EVT_OBJ_LOADED))
- return WTX_EVENT_OBJ_LOADED;
- else if (STREQ (str,WTX_EVT_OBJ_UNLOADED))
- return WTX_EVENT_OBJ_UNLOADED;
- else if (STREQ (str,WTX_EVT_CTX_START))
- return WTX_EVENT_CTX_START;
- else if (STREQ (str,WTX_EVT_CTX_EXIT))
- return WTX_EVENT_CTX_EXIT;
- else if (STREQ (str,WTX_EVT_EXCEPTION))
- return WTX_EVENT_EXCEPTION;
- else if (STREQ (str,WTX_EVT_VIO_WRITE))
- return WTX_EVENT_VIO_WRITE;
- else if (STREQ (str,WTX_EVT_TOOL_ATTACH))
- return WTX_EVENT_TOOL_ATTACH;
- else if (STREQ (str,WTX_EVT_TOOL_DETACH))
- return WTX_EVENT_TOOL_DETACH;
- else if (STREQ (str,WTX_EVT_TOOL_MSG))
- return WTX_EVENT_TOOL_MSG;
- else if (STREQ (str,WTX_EVT_TEXT_ACCESS))
- return WTX_EVENT_TEXT_ACCESS;
- else if (STREQ (str,WTX_EVT_DATA_ACCESS))
- return WTX_EVENT_DATA_ACCESS;
- else if (STREQ (str,WTX_EVT_CALL_RETURN))
- return WTX_EVENT_CALL_RETURN;
- else if (STREQ (str,WTX_EVT_USER))
- return WTX_EVENT_USER;
- else if (STREQ (str,WTX_EVT_TS_KILLED))
- return WTX_EVENT_TS_KILLED;
- else if (STREQ (str,WTX_EVT_EVTPT_ADDED))
- return WTX_EVENT_EVTPT_ADDED;
- else if (STREQ (str,WTX_EVT_EVTPT_DELETED))
- return WTX_EVENT_EVTPT_DELETED;
- else if (STREQ (str,WTX_EVT_UNKNOWN))
- return WTX_EVENT_UNKNOWN;
- else
- return WTX_EVENT_OTHER;
- }
- /*******************************************************************************
- *
- * wtxEventToStrType - convert a WTX event enumeration type to a string
- *
- * This routine is a string converter for the event type passed
- * to the target server. It is the wtxStrToEventType routine counterpart.
- *
- * If the event is not known , the WTX_EVENT_UNKNOWN string is returned.
- *
- * The event types are given by:
- *
- * EXPAND ../../../include/wtxtypes.h WTX_EVENT_TYPE
- *
- * RETURNS: a string representing the event, or WTX_EVENT_UNKNOWN on error.
- */
-
- const char * wtxEventToStrType
- (
- WTX_EVENT_TYPE event /* WTX Event */
- )
- {
- switch (event)
- {
- case WTX_EVENT_TGT_RESET:
- return WTX_EVT_TGT_RESET;
- case WTX_EVENT_SYM_ADDED:
- return WTX_EVT_SYM_ADDED;