c - 在 Eclipse 中调试 C 程序 : Failed to execute MI command: -data-disassemble

标签 c eclipse debugging libxml2

我正在 Eclipse 中开发一个 C 项目(名为 final_01),我的项目有以下文件:main.c、XMLdataCatcher.c、crc.c 和头文件 crc.h,我正在使用 libxml2 库。

我的 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”等等,但我给你看的行是突出显示的。

可能是什么问题?我迷路了你.u

这是我的生成文件:

################################################################################
# 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

子目录.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);
}

抱歉,代码太多,英语不好。

提前致谢。

意大利

最佳答案

您的代码存在一些问题。首先,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() 中使用它,您可能会遇到段错误。

如果您解决了这两件事,也许您的问题就会消失。你仍然有很多调试工作要做。祝你好运。

关于c - 在 Eclipse 中调试 C 程序 : Failed to execute MI command: -data-disassemble,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198233/

相关文章:

android - DDMS透视图完全没有显示eclipse 4.1

Python脚本在不同的行停止并且不抛出异常

python - 如何调试通过单元测试部分覆盖但在重用时产生错误结果的 Python 代码?

C 函数指针赋值警告

遍历列表元素时的 C 问题

c - 该命令在 C 中有效吗?

c++ - Eclipse C/C++ 显示错误但编译?

c++ - C/C++ 指针数组的内联强制转换(void**)

java - 为什么运行时找不到类?

ios - Xcode 调试器是否可以捕获违反 Apple 的 “App Transport Security” 策略的陷阱