我正在Eclipse中开发一个C项目(名为final_01),我的项目有以下文件:main.c,XMLdataCatcher.c,crc.c和头文件crc.h,我使用的是libxml2库。< / p>
我的eclipse编辑器显示没有错误但是当我尝试运行时我不能,这是eclipse调试器的输出:
00000001: Failed to execute MI command:
-data-disassemble -s 1 -e 121 -- 1
Error message from debugger back end:
No se puede acceder a la memoria en la dirección 0x1
实际上有很多这样的线,唯一改变的是“00000001”,“00000000”,“00000002”,“00000003”等,但是我显示的线条突出显示。< / p>
可能是什么问题?我失去了你。
这是我的makefile:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: libfinal_01
# Tool invocations
libfinal_01: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -nostartfiles -L/usr/include/libxml2/libxml -shared -o "libfinal_01" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(LIBRARIES) libfinal_01
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
subdir.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../crc.c \
../dataCatcherXML.c \
../main.c
OBJS += \
./crc.o \
./dataCatcherXML.o \
./main.o
C_DEPS += \
./crc.d \
./dataCatcherXML.d \
./main.d
# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -I/usr/include/libxml2/libxml -O0 -g3 -Wall -c -g -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -I/usr/include/libxml2 -lxml2 -lz -lm
@echo 'Finished building: $<'
@echo ' '
main.o: ../main.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -I/usr/include/libxml2/libxml -O0 -g3 -Wall -c -g -MMD -MP -MF"$(@:%.o=%.d)" -MT"main.d" -o "$@" "$<" -I/usr/include/libxml2 -lxml2 -lz -lm
@echo 'Finished building: $<'
@echo ' '
这是main.c
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <xmlmemory.h>
#include "crc.h"
#include <c14n.h>
#include <catalog.h>
#include <chvalid.h>
#include <debugXML.h>
#include <dict.h>
#include <DOCBparser.h>
#include <encoding.h>
#include <entities.h>
#include <globals.h>
#include <hash.h>
#include <HTMLparser.h>
#include <HTMLtree.h>
#include <list.h>
#include <nanoftp.h>
#include <nanohttp.h>
#include <parser.h>
#include <parserInternals.h>
#include <pattern.h>
#include <relaxng.h>
#include <SAX.h>
#include <SAX2.h>
#include <schemasInternals.h>
#include <schematron.h>
#include <threads.h>
#include <tree.h>
#include <uri.h>
#include <valid.h>
#include <xinclude.h>
#include <xlink.h>
#include <xmlautomata.h>
#include <xmlerror.h>
#include <xmlexports.h>
#include <xmlIO.h>
#include <xmlmodule.h>
#include <xmlreader.h>
#include <xmlregexp.h>
#include <xmlsave.h>
#include <xmlschemas.h>
#include <xmlschemastypes.h>
#include <xmlstring.h>
#include <xmlunicode.h>
#include <xmlversion.h>
#include <xmlwriter.h>
#include <xpath.h>
#include <xpathInternals.h>
#include <xpointer.h>
#define BIT_SINCRONIA 0X47
#define PID_PAT 0X00
#define table_pat 0x00
FILE *fp2;
int main() {
unsigned short bit_error = 0;
bit_error = bit_error << 15;
unsigned short init_payload = 1;
init_payload = init_payload << 14;
unsigned short transport_priority = 0;
transport_priority = transport_priority << 13;
unsigned short PID = PID_PAT;
PID = transport_priority ^ PID;
PID = bit_error ^ PID;
PID = PID ^ init_payload;
unsigned short PID1 = PID >> 8;
unsigned short PID2 = PID;
unsigned short cifrado_transporte = 0;
cifrado_transporte = cifrado_transporte << 6;
unsigned short campo_adaptacion = 1;
campo_adaptacion = campo_adaptacion << 4;
campo_adaptacion = campo_adaptacion ^ cifrado_transporte;
unsigned short contador_continuidad = 0;
contador_continuidad = contador_continuidad ^ campo_adaptacion;
unsigned short pointer_file = 0x00;
unsigned short table_tag = table_pat;
unsigned short contador_pmt = 2;
unsigned short longitud_final = (17 + 6 + contador_pmt) - 7;
unsigned short id_ts = 0xfeaa;
unsigned short identificador_nit_pat = 0x000;
if (table_tag == 0x0) {
unsigned char indica_seccion = 1;
indica_seccion = indica_seccion << 7;
unsigned char reservado = 3;
reservado = reservado << 4;
reservado = reservado ^ indica_seccion;
unsigned short longitud = longitud_final & 0xf00;
longitud = longitud >> 8;
longitud = longitud ^ reservado;
unsigned short longitud1 = longitud_final & 0x0ff;
unsigned short id_ts1 = id_ts & 0xff00; //0xfa ;
id_ts1 = id_ts1 >> 8;
unsigned short id_ts2 = id_ts & 0x00ff;
unsigned short version = 0x00;
version = version << 1;
version = version ^ 0xc0;
unsigned short current_next = 1;
current_next = current_next ^ version;
unsigned short seccion_number = 0x00;
unsigned short last_seccion_number = 0x00;
unsigned short nit_id1 = 0;
unsigned short nit_id2 = 0;
unsigned short pid_nit1 = 0xe0;
unsigned short pid_nit2 = 0x10;
unsigned short pmt_id[contador_pmt];
unsigned short pmt_pid[contador_pmt];
pmt_id[1] = 0XAA;
pmt_pid[1] = 0X99;
pmt_id[2] = 0XBB;
pmt_pid[2] = 0X88;
unsigned char crc1 = 00;
unsigned char crc2 = 00;
unsigned char crc3 = 00;
unsigned char crc4 = 00;
unsigned char byte[189];
byte[1] = BIT_SINCRONIA;
byte[2] = (char) PID1;
byte[3] = (char) PID2;
byte[4] = (char) contador_continuidad;
byte[5] = (char) pointer_file;
byte[6] = (char) table_tag;
byte[7] = (char) longitud;
byte[8] = (char) longitud1;
byte[9] = (char) id_ts1;
byte[10] = (char) id_ts2;
byte[11] = (char) current_next;
byte[12] = (char) seccion_number;
byte[13] = (char) last_seccion_number;
byte[14] = (char) nit_id1;
byte[15] = (char) nit_id2;
byte[16] = (char) pid_nit1;
byte[17] = (char) pid_nit2;
int i;
for (i = 1; i <= contador_pmt; i++) {
byte[17 + i] = (char) (pmt_id[i]);
byte[17 + 2 + i] = (char) (pmt_pid[i]);
}
printf("%i\n", (17 + 3 + contador_pmt - 1));
char aux[1024] = "";
fp2 = fopen("/home/practicante/ficheroprueba.txt", "w");
for (i = 1; i < 22; i++) {
fputc(byte[i], fp2);
sprintf(aux + strlen(aux), "%x", byte[i]);
printf("\n%i aux es %s\n", i, aux);
}
unsigned long crc123 = crcFast(aux, strlen(aux));
printf("The crcFast() is %X\n", crcFast(aux, strlen(aux)));
sprintf(aux + strlen(aux), "%X", crcFast(aux, strlen(aux)));
printf("\nTrama es %s\n", aux);
printf("ad %X", crc123);
crc1 = (crc123 & 0xff000000) >> 24;
crc2 = (crc123 & 0x00ff0000) >> 16;
crc3 = (crc123 & 0x0000ff00) >> 8;
crc4 = (crc123 & 0x000000ff);
fputc(crc1, fp2);
fputc(crc2, fp2);
fputc(crc3, fp2);
fputc(crc4, fp2);
fclose(fp2);
}
return 0;
}
这是datachcherxml.c
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <xmlmemory.h>
#include "crc.h"
#include <c14n.h>
#include <catalog.h>
#include <chvalid.h>
#include <debugXML.h>
#include <dict.h>
#include <DOCBparser.h>
#include <encoding.h>
#include <entities.h>
#include <globals.h>
#include <hash.h>
#include <HTMLparser.h>
#include <HTMLtree.h>
#include <list.h>
#include <nanoftp.h>
#include <nanohttp.h>
#include <parser.h>
#include <parserInternals.h>
#include <pattern.h>
#include <relaxng.h>
#include <SAX.h>
#include <SAX2.h>
#include <schemasInternals.h>
#include <schematron.h>
#include <threads.h>
#include <tree.h>
#include <uri.h>
#include <valid.h>
#include <xinclude.h>
#include <xlink.h>
#include <xmlautomata.h>
#include <xmlerror.h>
#include <xmlexports.h>
#include <xmlIO.h>
#include <xmlmodule.h>
#include <xmlreader.h>
#include <xmlregexp.h>
#include <xmlsave.h>
#include <xmlschemas.h>
#include <xmlschemastypes.h>
#include <xmlstring.h>
#include <xmlunicode.h>
#include <xmlversion.h>
#include <xmlwriter.h>
#include <xpath.h>
#include <xpathInternals.h>
#include <xpointer.h>
int XMLdataCatcher(int argc, char **argv) {
/*
*
* Declarando variables
*
* */
xmlDocPtr doc;
xmlNodePtr root;
xmlNodePtr node;
xmlNodePtr children;
xmlNodePtr children2;
char bit_error[1024] = "as";
/*
*
* Para leer el documento XML a través de internet esto NO SIRVE
* xmlParseFile (const char *filename);
*
* ESTO SI
* buffer = obtener_documento_xml("http://mi.servidor.com/gastos.xml");
* doc = xmlParseMemory(buffer, strlen(buffer));
*
* */
doc = xmlParseFile("/home/practicante/XML/prueba1.xml");
if (!doc) {
printf("Error al cargar documento XML\n");
}
root = xmlDocGetRootElement(doc);
node = root->xmlChildrenNode;
while (node != NULL ) {
children = node->xmlChildrenNode;
while (children != NULL ) {
if (!(xmlStrcmp(node->name, "bit_error"))) {
printf("%s: %s\n", node->name, xmlNodeGetContent(node));
printf("%s\n", bit_error);
strcpy(bit_error, xmlNodeGetContent(node));
printf("%s\n", bit_error);
}
children2 = children->xmlChildrenNode;
while (children2 != NULL ) {
printf("%s: %s\n", children->name, xmlNodeGetContent(children));
children2 = children2->next;
}
children = children->next;
}
node = node->next;
}
printf("bit_error2 = %d", 1);
return (1);
}
抱歉代码太多,我的英文不好。
提前致谢。
伊达
答案 0 :(得分:0)
您的代码存在一些问题。首先,contador_pmt为2,你将其编入索引:
unsigned short pmt_id[contador_pmt];
unsigned short pmt_pid[contador_pmt];
pmt_id[1] = 0XAA;
pmt_pid[1] = 0X99;
pmt_id[2] = 0XBB;
pmt_pid[2] = 0X88;
C数组索引从0开始,而不是1,所以带有2的引用是未定义的。该数组的有效索引是0和1.
其次,你没有检查fopen()的返回值为0.如果fopen()返回0并且你试图在fputc()中使用它,你可能会得到一个seg错误。
如果你解决了这两件事,也许你的问题就会消失。你仍然需要做很多调试。祝你好运。